Skip to content
Closed
Changes from 1 commit
Commits
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
fixup: address review comments
  • Loading branch information
HarshithaKP committed Mar 4, 2020
commit 59965cd015de0ae3fef12f0c7a7acf3a39b46a6c
19 changes: 9 additions & 10 deletions test/parallel/test-async-local-storage-http-multiclients.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
const common = require('../common');

const assert = require('assert');
const { AsyncLocalStorage } = require('async_hooks');
const http = require('http');
Expand All @@ -13,14 +12,14 @@ const NUM_CLIENTS = 10;
// 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
// 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 coalesced, and the callback in the client
// may be called only once, defeating the purpose of test
r.end((index++).toString().repeat(1024 * 1024));
// 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));
});

server.listen(0, common.mustCall(() => {
Expand All @@ -33,15 +32,16 @@ server.listen(0, common.mustCall(() => {

// Make ondata and onend non-closure
// functions and fully dependent on ALS
res.setEncoding('utf8');
res.on('data', ondata);
Comment thread
addaleax marked this conversation as resolved.
res.on('end', onend);
res.on('end', common.mustCall(onend));
}));
req.end();
}));
}
}));

// Accumulate the instantaneous data with the store data
// Accumulate the current data chunk with the store data
function ondata(d) {
const store = cls.getStore();
assert.notStrictEqual(store, undefined);
Expand All @@ -55,9 +55,8 @@ let endCount = 0;
function onend() {
const store = cls.getStore();
assert.notStrictEqual(store, undefined);
const chunk = store.get('data');
const re = new RegExp(chunk[0], 'g');
assert.strictEqual(chunk.replace(re, '').length, 0);
const data = store.get('data');
assert.strictEqual(data, data[0].repeat(data.length));
if (++endCount === NUM_CLIENTS) {
Comment thread
jasnell marked this conversation as resolved.
Outdated
server.close();
}
Expand Down