-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
84 additions
and
84 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
45 changes: 45 additions & 0 deletions
45
packages/dd-trace/test/debugger/devtools_client/json-buffer.spec.js
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,45 @@ | ||
'use strict' | ||
|
||
require('../../setup/mocha') | ||
|
||
const JSONBuffer = require('../../../src/debugger/devtools_client/json-buffer') | ||
|
||
const MAX_SAFE_SIGNED_INTEGER = 2 ** 31 - 1 | ||
|
||
describe('JSONBuffer', () => { | ||
it('should call onFlush with the expected payload when the timeout is reached', function (done) { | ||
const onFlush = (json) => { | ||
const diff = Date.now() - start | ||
expect(json).to.equal('[{"message":1},{"message":2},{"message":3}]') | ||
expect(diff).to.be.within(95, 110) | ||
done() | ||
} | ||
|
||
const jsonBuffer = new JSONBuffer({ size: Infinity, timeout: 100, onFlush }) | ||
|
||
const start = Date.now() | ||
jsonBuffer.write(JSON.stringify({ message: 1 })) | ||
jsonBuffer.write(JSON.stringify({ message: 2 })) | ||
jsonBuffer.write(JSON.stringify({ message: 3 })) | ||
}) | ||
|
||
it('should call onFlush with the expected payload when the size is reached', function (done) { | ||
const expectedPayloads = [ | ||
'[{"message":1},{"message":2}]', | ||
'[{"message":3},{"message":4}]' | ||
] | ||
|
||
const onFlush = (json) => { | ||
expect(json).to.equal(expectedPayloads.shift()) | ||
if (expectedPayloads.length === 0) done() | ||
} | ||
|
||
const jsonBuffer = new JSONBuffer({ size: 30, timeout: MAX_SAFE_SIGNED_INTEGER, onFlush }) | ||
|
||
jsonBuffer.write(JSON.stringify({ message: 1 })) // size: 15 | ||
jsonBuffer.write(JSON.stringify({ message: 2 })) // size: 29 | ||
jsonBuffer.write(JSON.stringify({ message: 3 })) // size: 15 (flushed, and re-added) | ||
jsonBuffer.write(JSON.stringify({ message: 4 })) // size: 29 | ||
jsonBuffer.write(JSON.stringify({ message: 5 })) // size: 15 (flushed, and re-added) | ||
}) | ||
}) |
45 changes: 0 additions & 45 deletions
45
packages/dd-trace/test/debugger/devtools_client/queue.spec.js
This file was deleted.
Oops, something went wrong.
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