-
Notifications
You must be signed in to change notification settings - Fork 13
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
Update to termtest v2 #2731
Update to termtest v2 #2731
Conversation
# Conflicts: # cmd/state-installer/test/integration/installer_int_test.go # go.sum # test/integration/auth_int_test.go # test/integration/bundle_int_test.go # test/integration/package_int_test.go # test/integration/push_int_test.go # test/integration/revert_int_test.go # vendor/modules.txt
…lementation did, despite the name
# Conflicts: # go.sum # test/integration/install_scripts_int_test.go # test/integration/update_int_test.go
# Conflicts: # internal/testhelpers/e2e/session.go
@mitchell-as I suggest giving the e2e changes a closer look, but to only review the rest at a very high level. |
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 was a herculean effort that you managed to pull off. No amount of applause is enough.
In addition to the overhaul, I like that you also added reasonable timeouts or removed unnecessary ones.
Nevertheless, there are a few things that we should probably address.
cp.Expect("Starting") | ||
time.Sleep(1 * time.Second) // wait for the service to start up | ||
cp.Signal(syscall.SIGINT) | ||
cp.Cmd().Process.Signal(syscall.SIGINT) |
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 is not very discoverable. Other uses of cp.Cmd()
are in session.go, which is fine for lower-level stuff, but high level stuff like sending process signal should be a top-level function in my opinion. Are you open to changing this back to cp.Signal(syscall.SIGINT)
?
Edit: is this any different than cp.SendCtrlC()
? Something to think about.
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.
Originally I had this implemented at a higher level, but it quickly becomes burdensome to handle these states when it comes to closing the connections when it's done. In the end I felt that making the command a responsibility of the consumer was better as it's rare that you even need to do this, and this way we're not trying to do too much with the termtest library.
Making it accessible via a Cmd()
method is itself already going slightly further than required as the command is fed into termtest by the consumer, so the consumer should already have access to this regardless.
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.
Okay, so this is different than cp.SendCtrlC()
?
@@ -187,6 +178,7 @@ func new(t *testing.T, retainDirs, updatePath bool, extraEnv ...string) *Session | |||
constants.OptinUnstableEnvVarName + "=true", | |||
constants.ServiceSockDir + "=" + dirs.SockRoot, | |||
constants.HomeEnvVarName + "=" + dirs.HomeDir, | |||
"NO_COLOR=true", |
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.
Can we either constantize this option or add a comment on what it does? I think I know what it means, but I'd like a comment somewhere to confirm.
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.
It's this way because it's an existing standard:
https://www.gnu.org/software/gettext/libtextstyle/manual/html_node/The-NO_005fCOLOR-variable.html
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 was not familiar with said standard. Would you add a brief comment please?
cp.ExpectLongString("Installation path must be an empty directory") | ||
cp.Wait() | ||
cp.Expect("Installation path must be an empty directory") | ||
cp.ExpectExit() |
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.
How about expecting a non-zero exit code? This looks like an error.
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 should've added a comment, cause I don't remember the specifics. But looking at the commit and the context I believe I did this because the exit code doesn't bubble up properly through powershell.
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 think it's better to have some comment here rather than none at all. If I saw this down the road I would be very tempted to change it to ExpectExitCode(0)
.
Thank you! Worth noting that I still want to work more on the timeouts, just not in this PR. I'd like to end up with a default timeout of 5 seconds, and have anything that needs more specifically state it. But as you might imagine that could itself take days to untangle. |
internal/testhelpers/e2e/session.go
Outdated
if spawnOpts.RunInsideShell { | ||
switch runtime.GOOS { | ||
case "windows": | ||
shell = "cmd.exe" |
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 see you added the Cmd
constant on line 295, but you didn't change the one here. Unless I'm missing something, best to be safe and change it here too, right?
cp.ExpectLongString("Installation path must be an empty directory") | ||
cp.Wait() | ||
cp.Expect("Installation path must be an empty directory") | ||
cp.ExpectExit() |
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 think it's better to have some comment here rather than none at all. If I saw this down the road I would be very tempted to change it to ExpectExitCode(0)
.
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.
Almost there!
No description provided.