-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Organize unit tests and add integration tests with hsd #101
Conversation
b6b8bba
to
2d70c4c
Compare
5f0903a
to
b1b4e85
Compare
8b1cd7f
to
0c0795c
Compare
12cb2b2
to
d1640e6
Compare
cc9eb6c
to
9810e34
Compare
waitForSync() { | ||
return new Promise((resolve, reject) => { | ||
// Hack | ||
setTimeout(() => { | ||
resolve(); | ||
}, 5000); | ||
|
||
// // TODO: Fix hnsd stdout parsing for chain height | ||
// setTimeout(() => { | ||
// reject(new Error('Timeout waiting for sync')); | ||
// }, 5000); | ||
// setInterval(() => { | ||
// if (this.hnsdHeight === this.node.chain.height) | ||
// resolve(); | ||
// }, 100); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waitForSync() { | |
return new Promise((resolve, reject) => { | |
// Hack | |
setTimeout(() => { | |
resolve(); | |
}, 5000); | |
// // TODO: Fix hnsd stdout parsing for chain height | |
// setTimeout(() => { | |
// reject(new Error('Timeout waiting for sync')); | |
// }, 5000); | |
// setInterval(() => { | |
// if (this.hnsdHeight === this.node.chain.height) | |
// resolve(); | |
// }, 100); | |
}); | |
} | |
async waitForSync() { | |
if (!this.hnsd || !this.hnsd.killed) { | |
return new Promise(resolve => setTimeout(resolve, 100)) | |
.then(() => this.waitForSync); | |
} | |
} |
this.hnsd.stdout.on('data', (data) => { | ||
// TODO: `data` is always 8192 bytes and output gets cut off, why? | ||
const chunk = data.toString('ascii'); | ||
const lines = chunk.split(/\n/); | ||
|
||
for (const line of lines) { | ||
const words = line.split(/\s+/); | ||
|
||
if (words[0] !== 'chain' || words.length < 2) | ||
continue; | ||
|
||
this.hnsdHeight = parseInt(words[1].slice(1, -2)); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.hnsd.stdout.on('data', (data) => { | |
// TODO: `data` is always 8192 bytes and output gets cut off, why? | |
const chunk = data.toString('ascii'); | |
const lines = chunk.split(/\n/); | |
for (const line of lines) { | |
const words = line.split(/\s+/); | |
if (words[0] !== 'chain' || words.length < 2) | |
continue; | |
this.hnsdHeight = parseInt(words[1].slice(1, -2)); | |
} | |
}); | |
this.hnsd.stdout.on('data', (data) => { | |
const chunk = data.toString('ascii'); | |
// check for "chain (xxx)" | |
const height = chunk.match(/chain \((?<height>\d+)\).*(?![\s\S]*chain)/)?.groups?.height; | |
if (height) | |
this.hnsdHeight = parseInt(height); | |
if (timer) | |
clearTimeout(timer); | |
if (!this.hnsd.killed) | |
timer = setTimeout(() => { | |
this.hnsd.kill(); | |
}, 200); | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: added command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool CI with 3 platforms! Both hnsd and integration tests work great locally.
I did forget to build for regtest (like the readme mentions) and the tests just timed out with no specific errors.
Can hnsd print the network name on start? It would help identify binaries and can also make the test suite confirm that it's build with the correct network. Just an idea, not blocking this PR.
"dependencies": { | ||
"bmocha": "^2.1.5", | ||
"bsert": "0.0.10", | ||
"hsd": "^4.0.1" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know bns
is installed because of hsd, but since the test script explicitly uses bns
, should be be included here?
Yeah re-building for each network is annoying, maybe we can work that out in the future and start hnsd with a network argument. I think we need to avoid using hnsd's stdout for anything important, and using HS class won't really work either since the "API" ports will be different for each network. I think the fastest solution to this may be a version command or something that could work like this:
|
@rithvikvibhu added in 1715b09
|
1715b09
to
d7b33e7
Compare
Sweet, version shows network and test fails. LGTM |
Closes #23
This cleans up the framework for unit tests (written C and compiled into executable
test_hnsd
) and also introduces a new integration test system using nodejs and hsd.