change files structure
This commit is contained in:
parent
3210e72b22
commit
1ed6449ac6
30 changed files with 7 additions and 7 deletions
96
server/test/executor_program_service_test.ts
Normal file
96
server/test/executor_program_service_test.ts
Normal file
|
@ -0,0 +1,96 @@
|
|||
import { delay } from "../src/core/helper/delay.js";
|
||||
import { EXEC_TYPE } from "../src/core/model/exec_error_model.js";
|
||||
import { ExecutorResult } from "../src/core/model/executor_result.js";
|
||||
import { ExecutorProgramService } from "../src/core/services/executor_program_service.js";
|
||||
import { TestCore } from "./core/test_core.js";
|
||||
import { resultTest as resultTest, __dirname } from "./test.js";
|
||||
import { Worker } from "node:cluster";
|
||||
|
||||
|
||||
|
||||
export class ExecutorProgramServiceTest extends ExecutorProgramService {
|
||||
timeCancel = 1000;
|
||||
public test = async () => {
|
||||
await this.resultsTests();
|
||||
await this.longTimeCancelTest()
|
||||
await this.logWriteAndEventEndTestTypeExec()
|
||||
await this.logWriteAndEventEndTypeSpawn()
|
||||
};
|
||||
private async logWriteAndEventEndTypeSpawn(){
|
||||
const executorProgramService = await new ExecutorProgramService(__dirname + '/')
|
||||
executorProgramService.call(EXEC_TYPE.SPAWN, 'node',['./mocks/log_code.js'])
|
||||
const test = TestCore.instance
|
||||
let testIsOk = false
|
||||
let logEvent = false
|
||||
|
||||
executorProgramService.on((e) =>{
|
||||
if(e.isSuccess()) {
|
||||
const executorResult = e.value as ExecutorResult
|
||||
if(logEvent == false){
|
||||
logEvent = executorResult.data != null && executorResult.data != undefined
|
||||
}
|
||||
testIsOk = executorResult.event == 'END' && logEvent
|
||||
}
|
||||
})
|
||||
await delay(8000)
|
||||
test.assert(testIsOk,'ExecutorProgramService EXEC_TYPE.SPAWN end event and log write')
|
||||
}
|
||||
private async logWriteAndEventEndTestTypeExec(){
|
||||
const executorProgramService = await new ExecutorProgramService(__dirname)
|
||||
executorProgramService.call(EXEC_TYPE.EXEC, 'node ./test/mocks/log_code.js' )
|
||||
const test = TestCore.instance
|
||||
executorProgramService.on((e) =>{
|
||||
if(e.isSuccess()) {
|
||||
const executorResult = e.value as ExecutorResult
|
||||
test.assert(executorResult.data != undefined && executorResult.event == 'END','ExecutorProgramService EXEC_TYPE.EXEC end event and log write')
|
||||
}
|
||||
})
|
||||
await delay(7000)
|
||||
}
|
||||
private async longTimeCancelTest(){
|
||||
const executorProgramService = await new ExecutorProgramService('',1000)
|
||||
executorProgramService.call(EXEC_TYPE.EXEC, 'node ./test/mocks/long_code.js' )
|
||||
await delay(1500)
|
||||
const worker = executorProgramService.worker as Worker
|
||||
const test = TestCore.instance
|
||||
test.assert(worker.isDead(),'ExecutorProgramService long time cancel')
|
||||
|
||||
}
|
||||
private resultsTests = async () => {
|
||||
await resultTest(
|
||||
new ExecutorProgramService(__dirname),
|
||||
[EXEC_TYPE.EXEC, "node ./mocks/error.js"],
|
||||
"ExecutorProgramService EXEC_TYPE.EXEC on Result.error",
|
||||
false,
|
||||
2000
|
||||
);
|
||||
await delay(400)
|
||||
await resultTest(
|
||||
new ExecutorProgramService(__dirname),
|
||||
[EXEC_TYPE.EXEC, "ls"],
|
||||
"ExecutorProgramService EXEC_TYPE.EXEC on Result.ok",
|
||||
true
|
||||
);
|
||||
|
||||
await resultTest(
|
||||
new ExecutorProgramService(__dirname),
|
||||
[EXEC_TYPE.SPAWN, "ls"],
|
||||
"ExecutorProgramService EXEC_TYPE.SPAWN on Result.ok",
|
||||
true
|
||||
);
|
||||
await resultTest(
|
||||
new ExecutorProgramService(__dirname),
|
||||
[EXEC_TYPE.SPAWN, "python3 ./mocks/s.js"],
|
||||
"ExecutorProgramService EXEC_TYPE.SPAWN on Result.error",
|
||||
false,
|
||||
2000
|
||||
);
|
||||
await resultTest(
|
||||
new ExecutorProgramService(__dirname),
|
||||
[EXEC_TYPE.SPAWN, "ls"],
|
||||
"ExecutorProgramService EXEC_TYPE.SPAWN on Result.ok",
|
||||
true,
|
||||
2000
|
||||
);
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue