Skip to content
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

Client: Add tests to verify shutdown #1641

Merged
merged 5 commits into from
Jan 18, 2022
Merged
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
11 changes: 7 additions & 4 deletions packages/client/test/cli/cli-rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ const cliArgs = ['--rpc', '--ws', '--dev', '--transports=rlpx']
const end = (child: ChildProcessWithoutNullStreams, hasEnded: boolean, st: tape.Test) => {
if (hasEnded) return
hasEnded = true
child.stdout.removeAllListeners()
child.stderr.removeAllListeners()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to keep these here in the end() function, but just after the new st.ok check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just gave up on checking for the exit message. If you remove them in function after the kill signal is sent, it removes them before the client prints the "Exiting..." message to the console so the test never registers. But the res value of true should be just as good because that SIGINT is what we listen for in the client to shut it down and if the result we get back is something screwy, that return value should be false in our test.

child.kill('SIGINT')
const res = child.kill('SIGINT')
st.ok(res === true, 'client shut down successfully')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
st.ok(res === true, 'client shut down successfully')
st.ok(res, 'client shut down successfully')

st.end()
}

Expand All @@ -21,7 +20,6 @@ tape('[CLI] rpc', (t) => {

child.stdout.on('data', async (data) => {
const message = data.toString()

if (message.includes('http://')) {
// if http endpoint startup message detected, call http endpoint with RPC method
const client = Client.http({ port: 8545 })
Expand Down Expand Up @@ -69,9 +67,14 @@ tape('[CLI] rpc', (t) => {
if (message.includes('address=ws://')) {
st.fail('ws endpoint should not be enabled')
}
if (message.includes('Exiting')) {
st.pass('client received shutdown signal')
}
if (message.includes('Miner: Assembling block')) {
st.pass('miner started and no rpc endpoints started')
end(child, hasEnded, st)
child.stdout.removeAllListeners()
child.stderr.removeAllListeners()
}
})

Expand Down