gpt4 book ai didi

testing - PM2 Testcafe fs 运行导致崩溃

转载 作者:行者123 更新时间:2023-11-28 21:36:05 25 4
gpt4 key购买 nike

如果我在 pm2 下使用 TestCafe 运行我的应用程序,如果 Testcafe 脚本使用 FS 操作,pm2 总是会崩溃。

        async function unlinkFiles () {
if(fs.existsSync(downloadsFolder()+'/export.xml')){
fs.unlinkSync(downloadsFolder()+'/export.xml');
}
if(fs.existsSync(downloadsFolder()+'/export.json')){
fs.unlinkSync(downloadsFolder()+'/export.json');
}
return true;
}

如果我注释掉这个 fs 操作,pm2 将不会在这个位置崩溃,但稍后会崩溃。所以每次在pm2下的TestCafe的脚本中使用FS操作,pm2都会崩溃。这是已知问题吗?

我的脚本:

import { Selector, ClientFunction } from 'testcafe'; 
import fs from "fs";
import downloadsFolder from "downloads-folder";
import xpath from 'xpath';
import jp from 'jsonpath';
import {DOMParser} from 'xmldom';

fixture `SMTest 1-11-2019 (23:31:12)`

const getStyleWidthInPercents = ClientFunction(() => {
var calVar = Math.min(100, parseInt(document.querySelector('.progress-bar.progress-bar-success').style.width)) + '%';
return calVar;
});

const compareValues = ClientFunction(test1 => {
const enumVar = document.querySelector(test1).innerHTML;
return enumVar;
});


test
.httpAuth({
username: 'xxx',
password: 'xxx'
})
('RV_mvK22', async t => {
console.log('tcafeprogress:0');
await t
.navigateTo("xxx")
.resizeWindow(1280, 720)

async function unlinkFiles () {
if(fs.existsSync(downloadsFolder()+'/export.xml')){
fs.unlinkSync(downloadsFolder()+'/export.xml');
}
if(fs.existsSync(downloadsFolder()+'/export.json')){
fs.unlinkSync(downloadsFolder()+'/export.json');
}
return true;
}

console.log('tcafeprogress:5');

await t
.expect(await unlinkFiles()).ok()

await t
.wait(2000)
.click(Selector('a').withText('Regelwerk'))
//.typeText(Selector('#settingsTable_filter').find('.form-control.input-sm'), 'tcafe')
//.wait(2000)
.click(Selector('button').withText('Upload'))

console.log('tcafeprogress:10');

await t
.setFilesToUpload(Selector('#fileupload'), ['./uploads/RV_mvk2.xml'])
.wait(2000)

//Cheap Developed UI with Workaround here
await t
.expect(getStyleWidthInPercents()).eql('100%', {timeout: 90000})

console.log('tcafeprogress:20');
await t
.wait(2000)
.click(Selector('.btn.btn-secondary.close-button[data-dismiss="modal"]'))
.wait(2000)


//Upload success, now search and create XML
.typeText(Selector('#settingsTable_filter').find('.form-control.input-sm'), 'RV_mvk2.xml')
.wait(2000)
//.debug()
.click(Selector('button').withText('Erstellen'))
console.log('tcafeprogress:30');

//Prüfen ob das Fenster zu geht, wenn nicht dann abbrechen.
//Vielleicht die ID Exists?
await t
.expect(Selector('#ContainerId').exists).ok('War wohl nicht erfolgreich',{ timeout: 300000 })

const korpusid = await Selector('#ContainerId').innerText;

console.log('tcafeprogress:40');

//If fail, please note that the report will always report one step more.
const value0 = await Selector('#KH').value
await t
.expect(compareValues('#KH_value')).eql(value0,'Wertvergleich fehlgeschlagen', {timeout: 40000})
const value1 = await Selector('#KB').value
await t
.expect(compareValues('#KB_value')).eql(value1,'Wertvergleich fehlgeschlagen', {timeout: 40000})
const value2 = await Selector('#KT').value
await t
.expect(compareValues('#KT_value')).eql(value2,'Wertvergleich fehlgeschlagen', {timeout: 40000})
const value3 = await Selector('#Plattendicke').value
await t
.expect(compareValues('#Plattendicke_value')).eql(value3,'Wertvergleich fehlgeschlagen', {timeout: 40000})
const value4 = await Selector('#Schiene_Size_x').value
await t
.expect(compareValues('#Size_x_value')).eql(value4,'Wertvergleich fehlgeschlagen', {timeout: 40000})
.wait(2000)


console.log('tcafeprogress:50');

//XML DOWNLOAD
await t
.click(Selector('button').withText('Aktionen'))
.click(Selector('a').withText('Xml Exportieren'));
await t
.wait(6000)
await t .expect(fs.existsSync(downloadsFolder()+'/export.xml')).ok()


//JSON DOWNLOAD
await t
.click(Selector('button').withText('Aktionen'))
.click(Selector('a').withText('Preis Exportieren'))
await t
.wait(6000)
await t.expect(fs.existsSync(downloadsFolder()+'/export.json')).ok()

console.log('tcafeprogress:70');


//Nun müssten das XML öffnen und XPATH lesen.
async function getXMLInfo (path,attr) {
var xml = fs.readFileSync(downloadsFolder()+'/export.xml', 'utf8').toString();
var doc = new DOMParser().parseFromString(xml);
var enumeration = '';
if(attr===true){
enumeration = xpath.select1(path, doc).value;
}else{
enumeration = xpath.select(path, doc);
}

var noXML = enumeration.toString();
noXML = noXML.replace(/\n| | /g, ' ');
noXML = noXML.replace(/ {1,}/g,' ');

console.log(noXML);
return noXML;
}

await t
.expect(await getXMLInfo('//CCSYSTEMCABINETID[1]/text()[1]',false)).eql(korpusid,'XML Wertvergleich fehlgeschlagen', {timeout: 40000})
await t
.expect(await getXMLInfo('//CabinetPart[@id=\'ID0001\'][1]/@name',true)).eql('Unterboden','XML Wertvergleich fehlgeschlagen', {timeout: 40000})
await t
.expect(await getXMLInfo('//ExternalPart[1]/@identifier',true)).eql('schiene_xyz','XML Wertvergleich fehlgeschlagen', {timeout: 40000})
await t
.expect(await getXMLInfo('//ExternalPart[1]/@length',true)).eql('1000','XML Wertvergleich fehlgeschlagen', {timeout: 40000})
await t
.expect(await getXMLInfo('//point[4]/@coordinate',true)).eql('1200 23 0','XML Wertvergleich fehlgeschlagen', {timeout: 40000})


console.log('tcafeprogress:80');

async function getJSONInfo (path) {
var xml = fs.readFileSync(downloadsFolder()+'/export.json', 'utf8').toString();

if(path==='$..*'){
console.log("Alles");
return xml;
}

var enumeration = jp.query(JSON.parse(xml), path);

console.log(enumeration.toString());
return enumeration.toString();
}

await t
.expect(await getJSONInfo('$..CumulatedList[1].Name')).eql('schiene_xyz','JSON Wertvergleich fehlgeschlagen', {timeout: 40000})


console.log('tcafeprogress:100');

});

PM2 随报告崩溃。我不知道为什么显示 JSON 错误,因为这一步没有 JSON 函数。通过使用 try and error 调试代码,我能够将问题减少到节点 fs 操作。

crash pm2

最佳答案

对于所有有类似问题的人。在我的例子中,问题是节点模块“下载文件夹”中的子进程 exec。删除 Exec 语句后,崩溃消失了。

关于testing - PM2 Testcafe fs 运行导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58690238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com