Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
dc5d445
build: macOS package notarization
rvagg Jan 22, 2020
8c6f80f
deps: update term-size with signed version
rvagg Jan 30, 2020
95cfd4f
doc: official macOS builds now on 10.15 + Xcode 11
rvagg Mar 4, 2020
5b9ce00
meta: move inactive collaborators to emeriti
Trott Mar 8, 2020
c5a3bfd
doc: add Ruben to TSC
mhdawson Mar 11, 2020
0594de4
deps: upgrade npm to 6.14.1
isaacs Feb 27, 2020
055b3b9
lib: change var to let/const
himself65 Mar 2, 2020
6e1f0fe
test: fix test-tls-env-extra-ca-file-load
ebickle Mar 3, 2020
04f2caa
src: refactor to more safe method
gengjiawen Mar 4, 2020
0dd6e4a
test: `buffer.write` with longer string scenario
HarshithaKP Mar 6, 2020
2232399
lib: use spread operator on cluster
himself65 Mar 6, 2020
2428afb
build: disable libstdc++ debug containers globally
bnoordhuis Jan 3, 2020
975d6b0
util: use a global symbol for `util.promisify.custom`
ExE-Boss Feb 7, 2020
038a463
doc: expand fs.watch caveats
bzoz Mar 10, 2020
969b0b7
repl: align preview with the actual executed code
BridgeAR Feb 24, 2020
4d744c3
test: refactor and simplify test-repl-preview
BridgeAR Mar 9, 2020
ce58e02
doc: update conditional exports recommendations
guybedford Mar 4, 2020
435fbbc
worker: allow URL in Worker constructor
aduh95 Feb 6, 2020
45513c0
test: use portable EOL
HarshithaKP Mar 5, 2020
32dbc7a
http2: rename counter in `mapToHeaders` inner loop
mkrawczuk Feb 28, 2020
fc2909a
test: add new scenario for async-local storage
HarshithaKP Mar 4, 2020
612ee7d
deps: V8: cherry-pick f9257802c1c0
mmarchini Mar 10, 2020
3845754
util: text decoding allows SharedArrayBuffer
bfarias-godaddy Mar 11, 2020
d2857c7
esm: port loader code to JS
addaleax Mar 7, 2020
3649a7e
test: verify that WASI errors are rethrown
cjihrig Mar 9, 2020
c906c40
deps: upgrade to libuv 1.35.0
cjihrig Mar 11, 2020
04843b9
tools: update to acorn@7.1.1
Trott Mar 14, 2020
0a22384
test: make test-memory-usage predictable
mmarchini Mar 12, 2020
3c0ce69
src: fix warn_unused_result compiler warning
cjihrig Mar 13, 2020
70fe3be
test: workaround for V8 8.1 inspector pause issue
mmarchini Mar 12, 2020
63bf0f1
src: find .text section using dl_iterate_phdr
Mar 13, 2020
29d7863
stream: don't emit 'finish' after 'error'
ronag Mar 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add new scenario for async-local storage
Add a new scenario of multiple clients sharing a single data
callback function managing their response data through
AsyncLocalStorage APIs

Refs: #32063
Refs: #32060
Refs: #32062 (comment)

Co-authored-by: Gireesh Punathil <gpunathi@in.ibm.com>

PR-URL: #32082
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
HarshithaKP authored and BridgeAR committed Mar 17, 2020
commit fc2909a96a3c48cafc6eeaab3f232ee23720c564
65 changes: 65 additions & 0 deletions test/parallel/test-async-local-storage-http-multiclients.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use strict';
const common = require('../common');
const Countdown = require('../common/countdown');
const assert = require('assert');
const { AsyncLocalStorage } = require('async_hooks');
const http = require('http');
const cls = new AsyncLocalStorage();
const NUM_CLIENTS = 10;

// Run multiple clients that receive data from a server
// in multiple chunks, in a single non-closure function.
// Use the AsyncLocalStorage (ALS) APIs to maintain the context
// and data download. Make sure that individual clients
// receive their respective data, with no conflicts.

// Set up a server that sends large buffers of data, filled
// with cardinal numbers, increasing per request
let index = 0;
const server = http.createServer((q, r) => {
// Send a large chunk as response, otherwise the data
// may be sent in a single chunk, and the callback in the
// client may be called only once, defeating the purpose of test
r.end((index++ % 10).toString().repeat(1024 * 1024));
});

const countdown = new Countdown(NUM_CLIENTS, () => {
server.close();
});

server.listen(0, common.mustCall(() => {
for (let i = 0; i < NUM_CLIENTS; i++) {
cls.run(new Map(), common.mustCall(() => {
const options = { port: server.address().port };
const req = http.get(options, common.mustCall((res) => {
const store = cls.getStore();
store.set('data', '');

// Make ondata and onend non-closure
// functions and fully dependent on ALS
res.setEncoding('utf8');
res.on('data', ondata);
res.on('end', common.mustCall(onend));
}));
req.end();
}));
}
}));

// Accumulate the current data chunk with the store data
function ondata(d) {
const store = cls.getStore();
assert.notStrictEqual(store, undefined);
let chunk = store.get('data');
chunk += d;
store.set('data', chunk);
}

// Retrieve the store data, and test for homogeneity
function onend() {
const store = cls.getStore();
assert.notStrictEqual(store, undefined);
const data = store.get('data');
assert.strictEqual(data, data[0].repeat(data.length));
countdown.dec();
}