-
Notifications
You must be signed in to change notification settings - Fork 32
Add basic client/cli test #176
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { spawn } from 'child_process' | ||
| import tape from 'tape' | ||
|
|
||
| tape('[CLI]', (t) => { | ||
| t.test('should begin downloading blocks', { timeout: 260000 }, (t) => { | ||
| const file = require.resolve('../../dist/bin/cli.js') | ||
| const child = spawn(process.execPath, [file]) | ||
|
|
||
| const timeout = setTimeout(() => { | ||
| child.kill('SIGINT') | ||
| t.fail('timed out before finishing') | ||
| t.end() | ||
| }, 240000) | ||
|
|
||
| const end = () => { | ||
| clearTimeout(timeout) | ||
| child.kill('SIGINT') | ||
| t.end() | ||
| } | ||
|
|
||
| child.stdout.on('data', (data) => { | ||
| const message = data.toString() | ||
| if (message.toLowerCase().includes('error')) { | ||
| t.fail(message) | ||
| end() | ||
| } | ||
| if (message.includes('Imported blocks')) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI If data chunk size exceeds 16Kb (default value for readableHighWaterMark), then it will be split into several chunks to fit 16Kb size limit. So it's possible to meet the situation, when some part of 'Imported block' is in the first chunk and other is in another. It could be highly possible if script writes big bunch of data in one libuv event loop cycle, not sure if Client will ever do it. But if it will, then there will be false negative tests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah good to know, thanks, I was wondering about how it may be chunked. Any suggestions on a better or more reliable way to parse the incoming data?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| t.pass('successfully imported blocks') | ||
| end() | ||
| } | ||
| // log for easier debugging | ||
| // eslint-disable-next-line no-console | ||
| console.log(message) | ||
| }) | ||
|
|
||
| child.stderr.on('data', (data) => { | ||
| const message = data.toString() | ||
| t.fail(`stderr: ${message}`) | ||
| end() | ||
| }) | ||
|
|
||
| child.on('close', (code) => { | ||
| if (code !== 0) { | ||
| t.fail(`child process exited with code ${code}`) | ||
| end() | ||
| } | ||
| }) | ||
| }) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.