-
Notifications
You must be signed in to change notification settings - Fork 106
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
print & log port bind failures, dns-related test coverage, test improvements #239
Conversation
@@ -98,7 +98,7 @@ workflows: | |||
version: 2 | |||
test: | |||
jobs: | |||
- test_high_sierra | |||
# - test_high_sierra |
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 only used in my fork, but high sierra is flaking a lot, so turning off for now.
@@ -17,7 +17,7 @@ import ( | |||
var ( | |||
fDebug = flag.Bool("debug", false, "enable debug output") | |||
fDomains = flag.String("d", "test", "domains to handle, separate with :, defaults to test") | |||
fPort = flag.Int("dns-port", 9253, "port to listen on dns for") | |||
fDNSPort = flag.Int("dns-port", 9253, "port to listen on dns for") |
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.
give this flag variable a better name
go func() { | ||
if err := dns.Serve(domains); err != nil { | ||
fmt.Printf("! DNS Server failed: %v\n", err) | ||
} |
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.
check the return of dns.Serve
go func() { | ||
if err := http.ServeTLS(tlsSocketName); err != nil { | ||
fmt.Printf("! HTTPS Server failed: %v\n", err) | ||
} |
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.
check the return of http.ServeTLS
Address string | ||
Address string | ||
udpServer *dns.Server | ||
tcpServer *dns.Server |
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.
expose pointers to the servers were running internally, so we can shut them down gracefully in tests.
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.
also, use a constructor so these pointers exist before calling Serve
.
|
is there really no way to specify test-only dependencies? move unexported methods to the bottom first pass at catching errors from dns port bind refactor to use tomb over chan expose errors in listening for TLS and DNS remove default error handling. bail if we didn't get a good address remove "debug" messaging about not regenerating keypair nevermind -- most folks don't run this interactively, and its handy to have it in the log for now, just skip dns tests outside darwin fix compile error
skip high_sierra for now. fsevents are broken loop over tcp, udp go mod tidy map[string](func() interface{}) is awesome. refactor stdout capture to use return function instead of passed function call forgot one see if waiting for the shutdown to finish helps assert serve doesn't serve an error either only try to shutdown the server if we have a handle to it defer shutdown and fail if unable to shutdown remove timeout. we'll see if that fails. remove error stubs use constructor to init dns servers to avoid race remove retry print missed one shorten timeout, add comments to clarify intent of retries
only run one server per set of server test scenarios, so os.Exit will handle the cleanup put shutdown back inside main -- it calls os.Exit() which borks testing pull out additional state into each platform spec ensure we run things on completely non-standard ports missed an import
74ec30c
to
8fcf220
Compare
|
||
configureAndBootPumaDevServer(t, map[string]string{ | ||
"dir": appLinkDir, | ||
"dns-port": "65053", |
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.
we need platform specific server runs here, because darwin supports some flags that linux doesn't support.
"https-port": "65443", | ||
}) | ||
|
||
runPlatformAgnosticTestScenarios(t) |
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.
most examples are shared, but platform-specific stuff can live in each file.
stop := make(chan os.Signal, 1) | ||
|
||
signal.Notify(stop, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM) | ||
shutdown := make(chan os.Signal, 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.
just a rename here.
|
||
assert.True(t, ok) | ||
assert.False(t, exit.Success()) | ||
} |
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.
diff is pretty useless here, since i reordered and renamed a bunch of the private methods.
type DNSResponder struct { | ||
Address string | ||
Domains []string |
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.
now a single DNSResponder
instance is bound to its domains, rather than being able to call Serve
multiple times with diff arguments on the same instance.
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.
Looks goooooooood!
This PR addresses a bug discovered while triaging #237.
Currently, puma-dev only fails to start it can't bind to the configured http port. If the tls or dns goroutines fail (often because the port is already taken), they do so silently and the user is led to believe that everything worked. This change ensures that port bind failures show up in logs and/or stdout if you're running interactively.
Changes
tomb.Tomb
indns.go
to allow for easy return of errorsexposethis ends up callingmain.shutdown
channel for better control over the puma-dev server launched in tests. This way, each test that needs to boot its own puma-dev server can correctly clean up after itself.os.Exit(0)
and we lose test failures, so pulled back on this approach.restart.txt
related tests to often (but not always) fail.Demo
Old
New