-
Notifications
You must be signed in to change notification settings - Fork 952
feat: added executor tests #1816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3403337
2edc3db
3502ba5
3bedaa2
d332a98
9dd7c25
6bf32ce
b4cd1b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| import { TestRunner } from "./tester"; | ||
|
|
||
| export async function runExecutorTests(writeOutput) { | ||
| const runner = new TestRunner("Executor API Tests"); | ||
|
|
||
| runner.test("Executor available", async (test) => { | ||
| test.assert(typeof Executor !== "undefined", "Executor should be available globally"); | ||
| }); | ||
|
|
||
| runner.test("Background Executor available", async (test) => { | ||
| test.assert(typeof Executor.BackgroundExecutor !== "undefined", "Background Executor should be available globally"); | ||
| }); | ||
|
|
||
|
|
||
| runner.test("execute()", async (test) => { | ||
|
|
||
| test.assert( | ||
| await Executor.execute("echo test123").includes("test123"), | ||
| "Command output should match" | ||
| ); | ||
|
|
||
| }); | ||
|
|
||
|
|
||
|
|
||
| runner.test("execute() (BackgroundExecutor)", async (test) => { | ||
|
|
||
| test.assert( | ||
| await Executor.BackgroundExecutor.execute("echo test123").includes("test123"), | ||
| "Command output should match" | ||
| ); | ||
|
|
||
| }); | ||
|
|
||
| runner.test("start()", async (test) => { | ||
| let stdout = ""; | ||
|
|
||
| const uuid = await Executor.start("sh", (type, data) => { | ||
| if (type === "stdout") stdout += data; | ||
| }); | ||
|
|
||
| await Executor.write(uuid, "echo hello\n"); | ||
|
|
||
| await Executor.stop(uuid); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
| test.assert(stdout.includes("hello"), "Shell should echo output"); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential timing issue: The test stops the executor at line 44, then waits 200ms at line 46, and then checks the output at line 48. However, the callback on line 38-40 may receive output asynchronously after the stop() call. This test might pass or fail intermittently depending on timing. Consider waiting before calling stop() to ensure all output has been received, or add an exit event handler to the callback to know when the process has truly finished. Prompt To Fix With AIThis is a comment left during a code review.
Path: src/test/exec.tests.js
Line: 35:49
Comment:
Potential timing issue: The test stops the executor at line 44, then waits 200ms at line 46, and then checks the output at line 48. However, the callback on line 38-40 may receive output asynchronously after the stop() call. This test might pass or fail intermittently depending on timing.
Consider waiting before calling stop() to ensure all output has been received, or add an exit event handler to the callback to know when the process has truly finished.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
|
|
||
| runner.test("start() (BackgroundExecutor)", async (test) => { | ||
| let stdout = ""; | ||
|
|
||
| const uuid = await Executor.start("sh", (type, data) => { | ||
| if (type === "stdout") stdout += data; | ||
| }); | ||
|
|
||
| await Executor.write(uuid, "echo hello\n"); | ||
| await Executor.stop(uuid); | ||
|
RohitKushvaha01 marked this conversation as resolved.
Outdated
|
||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
| test.assert(stdout.includes("hello"), "Shell should echo output"); | ||
| }); | ||
|
|
||
|
|
||
| runner.test("start/stop()", async (test) => { | ||
| let stdout = ""; | ||
|
|
||
| const uuid = await Executor.start("sh", (type, data) => { | ||
|
|
||
| }); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
|
|
||
| const isRunning = await Executor.isRunning(uuid); | ||
|
|
||
| test.assert(isRunning === true, "Executor must be running"); | ||
|
|
||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
| await Executor.stop(uuid); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
| test.assert(isRunning !== await Executor.isRunning(uuid), "Executor must be stopped"); | ||
|
RohitKushvaha01 marked this conversation as resolved.
Outdated
|
||
| test.assert(await Executor.isRunning(uuid) === false, "Executor must be stopped"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Race condition: The logic on line 92 is redundant with line 93, which properly checks the current state. Line 92 should be removed, or the test should be restructured to properly verify both running and stopped states separately. Prompt To Fix With AIThis is a comment left during a code review.
Path: src/test/exec.tests.js
Line: 79:93
Comment:
Race condition: `isRunning` is captured at line 79 (before stop), then the executor is stopped at line 87, and finally line 92 checks if `isRunning !== await Executor.isRunning(uuid)`. This assertion will always pass because it compares the old value (true) with the new value (false), but this doesn't actually verify that the stop operation worked correctly - it only verifies that the value changed.
The logic on line 92 is redundant with line 93, which properly checks the current state. Line 92 should be removed, or the test should be restructured to properly verify both running and stopped states separately.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| }); | ||
|
RohitKushvaha01 marked this conversation as resolved.
Outdated
|
||
|
|
||
| runner.test("start/stop() (BackgroundExecutor)", async (test) => { | ||
| let stdout = ""; | ||
|
|
||
| const uuid = await Executor.start("sh", (type, data) => { | ||
|
|
||
| }); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
|
|
||
| const isRunning = await Executor.isRunning(uuid); | ||
|
|
||
| test.assert(isRunning === true, "Executor must be running"); | ||
|
|
||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
| await Executor.stop(uuid); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
| test.assert(isRunning !== await Executor.isRunning(uuid), "Executor must be stopped"); | ||
| test.assert(await Executor.isRunning(uuid) === false, "Executor must be stopped"); | ||
|
RohitKushvaha01 marked this conversation as resolved.
Outdated
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Race condition: Same issue as in the previous start/stop() test. Line 121 is redundant with line 122, which properly checks the current state. Line 121 should be removed. Prompt To Fix With AIThis is a comment left during a code review.
Path: src/test/exec.tests.js
Line: 108:122
Comment:
Race condition: Same issue as in the previous start/stop() test. `isRunning` is captured at line 108 (before stop), then the executor is stopped at line 116, and line 121 checks if `isRunning !== await Executor.isRunning(uuid)`. This assertion will always pass but doesn't properly verify the stop operation worked - it only verifies that the value changed.
Line 121 is redundant with line 122, which properly checks the current state. Line 121 should be removed.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is labeled "start/stop() (BackgroundExecutor)" but it's actually testing the regular Executor, not BackgroundExecutor. Lines 100, 108, 116, 121, and 122 all use To properly test BackgroundExecutor, these calls should use Prompt To Fix With AIThis is a comment left during a code review.
Path: src/test/exec.tests.js
Line: 97:124
Comment:
This test is labeled "start/stop() (BackgroundExecutor)" but it's actually testing the regular Executor, not BackgroundExecutor. Lines 100, 108, 116, 121, and 122 all use `Executor.start()`, `Executor.isRunning()`, and `Executor.stop()` instead of `Executor.BackgroundExecutor.*` methods.
To properly test BackgroundExecutor, these calls should use `Executor.BackgroundExecutor` like the execute() test does on line 29.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| runner.test("start/stop()", async (test) => { | ||
| let stdout = ""; | ||
|
|
||
| const uuid = await Executor.start("sh", (type, data) => { | ||
|
|
||
| }); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
|
|
||
| const isRunning = await Executor.isRunning(uuid); | ||
|
|
||
| test.assert(isRunning === true, "Executor must be running"); | ||
|
|
||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
| await Executor.stop(uuid); | ||
|
|
||
| await new Promise(r => setTimeout(r, 200)); | ||
|
|
||
|
|
||
| test.assert(isRunning !== await Executor.isRunning(uuid), "Executor must be stopped"); | ||
| test.assert(await Executor.isRunning(uuid) === false, "Executor must be stopped"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Race condition: Same issue as in the other start/stop() tests. Line 155 is redundant with line 156. Line 155 should be removed. Prompt To Fix With AIThis is a comment left during a code review.
Path: src/test/exec.tests.js
Line: 142:156
Comment:
Race condition: Same issue as in the other start/stop() tests. `isRunning` is captured at line 142 (before stop), then the executor is stopped at line 150, and line 155 checks if `isRunning !== await Executor.isRunning(uuid)`. This assertion will always pass but doesn't properly verify the stop operation.
Line 155 is redundant with line 156. Line 155 should be removed.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| }); | ||
|
RohitKushvaha01 marked this conversation as resolved.
Outdated
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate test name "start/stop()". This test has the exact same name as the test on line 68, which will cause issues with test reporting and make it difficult to identify which test failed. This should have a unique name like "start/stop() lifecycle" or be removed if it's an accidental duplicate. Prompt To Fix With AIThis is a comment left during a code review.
Path: src/test/exec.tests.js
Line: 131:158
Comment:
Duplicate test name "start/stop()". This test has the exact same name as the test on line 68, which will cause issues with test reporting and make it difficult to identify which test failed. This should have a unique name like "start/stop() lifecycle" or be removed if it's an accidental duplicate.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| runner.test("FDROID env variable", async (test) => { | ||
| const result = await Executor.execute("echo $FDROID"); | ||
|
|
||
| const isSet = result.trim().length > 0; | ||
|
|
||
| test.assert( | ||
| isSet, | ||
| "FDROID env variable should be set" | ||
| ); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Environment-dependent test: This test assumes the FDROID environment variable is always set and has a non-empty value. However, this may not be true in all test environments (e.g., local development, CI/CD pipelines, non-F-Droid builds). Consider using Prompt To Fix With AIThis is a comment left during a code review.
Path: src/test/exec.tests.js
Line: 160:169
Comment:
Environment-dependent test: This test assumes the FDROID environment variable is always set and has a non-empty value. However, this may not be true in all test environments (e.g., local development, CI/CD pipelines, non-F-Droid builds).
Consider using `test.skip()` if the environment variable isn't set, or adjust the assertion to handle cases where the variable legitimately might not exist: `test.assert(typeof result === 'string', "FDROID env variable should be accessible")`
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| return await runner.run(writeOutput); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.