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

fix: initialize socketPath to prevent stale cache #491

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

holmanb
Copy link
Member

@holmanb holmanb commented Aug 21, 2024

daemonSuite.socketPath appears to be assigned outside of the test, but only when it has a default value, which results in a stale socketPath value in this test.

>  github.com/canonical/pebble/internals/daemon.(*daemonSuite).TestAddCommand() ./internals/daemon/daemon_test.go:186 (PC: 0xc17eef)
   181:	}
   182:	
   183:	func (s *daemonSuite) TestAddCommand(c *C) {
   184:		const endpoint = "/v1/addedendpoint"
   185:		var handler fakeHandler
=> 186:		getCallback := func(c *Command, r *http.Request, s *UserState) Response {
   187:			handler.cmd = c
   188:			return &handler
   189:		}
   190:		command := Command{
   191:			Path:       endpoint,
(dlv) print s
("*github.com/canonical/pebble/internals/daemon.daemonSuite")(0xc0000d4b80)
*github.com/canonical/pebble/internals/daemon.daemonSuite {
	pebbleDir: "/tmp/check-3911358415/1",
	socketPath: "/tmp/check-3190005390/10/custom.socket",
	httpAddress: ":0",
	statePath: "/tmp/check-3911358415/1/.pebble.state",
	authorized: false,
	err: error nil,
	notified: []string len: 0, cap: 0, nil,
	restoreBackends: nil,}
(dlv) q

Notice that in the above, the value in socketpath is not a subdirectory of the value in pebbleDir.

Running go test -count=2 -v ./internals/daemon -check.v with this fix now passes:

--- PASS: Test (7.22s)
PASS
ok  	github.com/canonical/pebble/internals/daemon	13.431s

Fixes #282.

Copy link
Contributor

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

@benhoyt benhoyt merged commit 9c9e95a into canonical:master Aug 21, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Daemon tests fail with nil pointer panic when run twice
2 participants