From 30207985cca8fc3e8fcfc3e27901e2166beb9ced Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Mon, 16 Mar 2020 10:59:39 -0400 Subject: [PATCH] test: als variant of test-timers-clearImmediate Refs: https://github.com/nodejs/node/issues/31978 PR-URL: https://github.com/nodejs/node/pull/32303 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- .../test-timers-clearImmediate-als.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/parallel/test-timers-clearImmediate-als.js diff --git a/test/parallel/test-timers-clearImmediate-als.js b/test/parallel/test-timers-clearImmediate-als.js new file mode 100644 index 00000000000000..bf2bc6b8d5a175 --- /dev/null +++ b/test/parallel/test-timers-clearImmediate-als.js @@ -0,0 +1,28 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const { AsyncLocalStorage } = require('async_hooks'); + +// This is an asynclocalstorage variant of test-timers-clearImmediate.js +const asyncLocalStorage = new AsyncLocalStorage(); +const N = 3; + +function next() { + const fn = common.mustCall(onImmediate); + asyncLocalStorage.run(new Map(), common.mustCall(() => { + const immediate = setImmediate(fn); + const store = asyncLocalStorage.getStore(); + store.set('immediate', immediate); + })); +} + +function onImmediate() { + const store = asyncLocalStorage.getStore(); + const immediate = store.get('immediate'); + assert.strictEqual(immediate.constructor.name, 'Immediate'); + clearImmediate(immediate); +} + +for (let i = 0; i < N; i++) { + next(); +}