Skip to content

chore(integration): update TestLogs to validate that CODER_ASGENT_SUBSYSTEM is set correctly #397

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

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
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
25 changes: 24 additions & 1 deletion integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ func TestLogs(t *testing.T) {
"Dockerfile": fmt.Sprintf(`FROM %s`, testImageUbuntu),
},
})
_, err := runEnvbuilder(t, runOpts{env: []string{
ctrID, err := runEnvbuilder(t, runOpts{env: []string{
envbuilderEnv("GIT_URL", srv.URL),
"CODER_AGENT_URL=" + logSrv.URL,
"CODER_AGENT_TOKEN=" + token,
"ENVBUILDER_INIT_SCRIPT=env",
}})
require.NoError(t, err)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
Expand All @@ -136,6 +137,28 @@ func TestLogs(t *testing.T) {
t.Fatal("timed out waiting for logs")
case <-logsDone:
}

// Wait for the container to exit
client, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
require.NoError(t, err)
require.Eventually(t, func() bool {
status, err := client.ContainerInspect(ctx, ctrID)
if !assert.NoError(t, err) {
return false
}
return !status.State.Running
}, 10*time.Second, time.Second, "container never exited")
Copy link
Member

Choose a reason for hiding this comment

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

Could 10 seconds be potentially flaky?

Copy link
Member Author

Choose a reason for hiding this comment

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

Potentially, but I think it's relatively unlikely that it will take that long to execute env and for the container to exit.


// Check the expected log output
logReader, err := client.ContainerLogs(ctx, ctrID, container.LogsOptions{
ShowStdout: true,
ShowStderr: true,
})
require.NoError(t, err)
logBytes, err := io.ReadAll(logReader)
require.NoError(t, err)
logs := string(logBytes)
require.Contains(t, logs, "CODER_AGENT_SUBSYSTEM=envbuilder")
Copy link
Member

Choose a reason for hiding this comment

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

Is this relevant for the logs test, or just something we want to verify in general? Would it make more sense in a more env-targeted test or some other behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

It only gets set if CODER_AGENT_URL and CODER_AGENT_TOKEN are set. It's not set otherwise. This is more of a convenient place to co-locate it.

}

func TestInitScriptInitCommand(t *testing.T) {
Expand Down