-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(daemon): Add cancellation context tests
Adds unit tests for using the cancellation context in both confined and unconfined plugins / caplets. Deletes some unused args and fixes some type issues discovered in the course of work. Also, adds docstrings to the Context interface in types.d.ts. In the course of implementation, a bug was discovered. The added tests only pass due to the addition of a delay that should not be necessary. The following applies the same to both the confined and unconfined cases. The tests are structured as follows: ``` 1 const result = E(host).evaluate( 2 'worker', 3 'E(caplet).awaitCancellation()', 4 ['caplet'], 5 ['context-consumer'], 6 ); 7 await E(host).cancel('context-consumer'); 8 t.is(await result, 'cancelled'); ``` The test endo.log reveals the cause: ``` Making make-unconfined:1f440... Making least-authority:abc51... Cancelled: * make-unconfined:1f440... Making eval:c9ae8... Making make-unconfined:1f440... ``` Despite receiving the `evaluate` request first and the cancellation request second, the host processes these requests in reverse order. The result is that the test hangs. As a temporary fix, a timeout is added on line 6. This bug will be fixed in a future commit.
- Loading branch information
Showing
5 changed files
with
141 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { E, Far } from '@endo/far'; | ||
|
||
export const make = async (_powers, context) => { | ||
return Far('Context consumer', { | ||
async awaitCancellation() { | ||
try { | ||
await E(context).whenCancelled(); | ||
} catch { | ||
return 'cancelled'; | ||
} | ||
throw new Error('should have been cancelled'); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters