From 6803c25083c166ee6bb83051b6876e764caedc09 Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Mon, 16 Mar 2020 10:59:39 -0400 Subject: [PATCH 1/3] test: als variant of test-timers-clearImmediate Refs: https://github.com/nodejs/node/issues/31978 --- .../test-timers-clearImmediate-als.js | 24 +++++++++++++++++++ 1 file changed, 24 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..1e37fc5c5b759f --- /dev/null +++ b/test/parallel/test-timers-clearImmediate-als.js @@ -0,0 +1,24 @@ +'use strict'; +const common = require('../common'); +const { AsyncLocalStorage } = require('async_hooks'); +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'); + clearImmediate(immediate); +} + +for (let i = 0; i < N; i++) { + next(); +} From 181b84c5ae6074d7e6e2835fd7a0e4cfbe7e5077 Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Mon, 16 Mar 2020 11:24:48 -0400 Subject: [PATCH 2/3] fixup: add one liner comment about test case --- test/parallel/test-timers-clearImmediate-als.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/parallel/test-timers-clearImmediate-als.js b/test/parallel/test-timers-clearImmediate-als.js index 1e37fc5c5b759f..ef6e477194847c 100644 --- a/test/parallel/test-timers-clearImmediate-als.js +++ b/test/parallel/test-timers-clearImmediate-als.js @@ -1,6 +1,8 @@ 'use strict'; const common = require('../common'); const { AsyncLocalStorage } = require('async_hooks'); + +// This is an asynclocalstorage variant of test-timers-clearImmediate.js const asyncLocalStorage = new AsyncLocalStorage(); const N = 3; From 087829b5b5a54058f6686d50f0dc711316bb921e Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Tue, 17 Mar 2020 01:22:57 -0400 Subject: [PATCH 3/3] fixup: address review comment --- test/parallel/test-timers-clearImmediate-als.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/parallel/test-timers-clearImmediate-als.js b/test/parallel/test-timers-clearImmediate-als.js index ef6e477194847c..bf2bc6b8d5a175 100644 --- a/test/parallel/test-timers-clearImmediate-als.js +++ b/test/parallel/test-timers-clearImmediate-als.js @@ -1,5 +1,6 @@ '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 @@ -18,6 +19,7 @@ function next() { function onImmediate() { const store = asyncLocalStorage.getStore(); const immediate = store.get('immediate'); + assert.strictEqual(immediate.constructor.name, 'Immediate'); clearImmediate(immediate); }