Commit bbe6af2
Add timeout (#147)
* Add runOptions.timeout
This commit adds new `runOptions.timeout` and `runOptions.killSignal`
options that allow a process to be killed after a specified number of
milliseconds have elapsed. See the [Node ChildProcess docs](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options).
This commit includes several additional changes that were necessary as
part of the implementation of `timeout`:
* Fix to `JavaCallerTester.java` that replaces an `==` string comparison
with a `args[0].equals("--sleep")`. This fixes the `sleep` command line
argument, which previously never triggered because the comparison
was always false.
* Recompile `JavaCallerTester.class` and `JavaCallerTester.jar`
* Fixed `should call JavaCallerTester.class detached` test. This began
failing after the call fix for `--sleep`. The test has been rewritten to
demonstrate the expected behavior for `detached`. Now, the test will
check that the Java process is initially still running and then check
the return status code once it exits.
* Update the NPM script `java:compile` to use `--release 8` instead of
`-source 8 -target 1.8`. This fixes an error that occurred when running
the previous script:
>warning: [options] bootstrap class path is not set in conjunction with -source 8
not setting the bootstrap class path may lead to class files that cannot run on JDK 8
--release 8 is recommended instead of -source 8 -target 1.8 because it sets the bootstrap class path automatically
See [this StackOverflow post](https://stackoverflow.com/a/61715683) for
more details.
Note that a warning is still generated:
>warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
Fixes #144
* Add to changelog
* Add timeout options to JavaCallerRunOptions type
* Remove null check for code when checking for timeout
This commit removes the check for `exitCode === null`, which will only
be the case on Windows. On Linux, the `exitCode` will be populated.
The [Node docs](https://nodejs.org/api/child_process.html#event-exit), say:
>The exit code if the child process exited on its own, or null if the child process terminated due to a signal.
>The 'exit' event is emitted after the child process ends. If the process exited, code is the final exit code of the process, otherwise null.
* Fix killSignal default in TypeScript docs
* Remove no-undef ESLint check for *.ts files
As recommended in the [TypeScript ESLint docs](https://typescript-eslint.io/troubleshooting/faqs/eslint#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors),
the `no-undef` rule should not be used for `*.ts` files because it
gives false positives. This causes issues with using `NodeJS.Signals`
in `index.d.ts`.
* Add temporary logging
* Handle cross-platform timeout
* unify timeout codes
* Simplify timeout logic
This commit simplifies the timeout logic by no longer passing `timeout`
to `spawn`. Instead, the full timeout logic is handled by `run`, which
sets a timeout and determines whether the process was killed. Now that
there is no duplicate logic, `wasKilledByTimeout` can be removed
in favor of checking `killedByTimeout` directly.
* Remove unused variable
---------
Co-authored-by: Nicolas Vuillamy <nicolas.vuillamy@gmail.com>1 parent 639f49b commit bbe6af2
File tree
11 files changed
+112
-12
lines changed- lib
- test
- java
- dist/com/nvuillam/javacaller
- jar
- src/com/nvuillam/javacaller
11 files changed
+112
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
120 | 134 | | |
121 | 135 | | |
122 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| |||
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
| 89 | + | |
87 | 90 | | |
88 | 91 | | |
89 | 92 | | |
| |||
97 | 100 | | |
98 | 101 | | |
99 | 102 | | |
100 | | - | |
| 103 | + | |
101 | 104 | | |
102 | 105 | | |
103 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
104 | 110 | | |
105 | 111 | | |
106 | 112 | | |
| |||
117 | 123 | | |
118 | 124 | | |
119 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
120 | 139 | | |
121 | 140 | | |
122 | 141 | | |
| |||
132 | 151 | | |
133 | 152 | | |
134 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
135 | 159 | | |
136 | 160 | | |
137 | 161 | | |
138 | 162 | | |
139 | 163 | | |
140 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
141 | 176 | | |
142 | 177 | | |
143 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
35 | 38 | | |
36 | | - | |
37 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
| |||
187 | 199 | | |
188 | 200 | | |
189 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
190 | 236 | | |
Binary file not shown.
Binary file not shown.
Binary file not shown.
0 commit comments