-
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
Changes from 7 commits
9f51e4d
b58e3f1
d65a2ff
8fcf220
d05d2ea
0c27432
6a656d7
15870c2
082e44b
b1474bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ workflows: | |
version: 2 | ||
test: | ||
jobs: | ||
- test_high_sierra | ||
# - test_high_sierra | ||
- test_mojave | ||
- test_catalina | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. give this flag variable a better name |
||
fHTTPPort = flag.Int("http-port", 9280, "port to listen on http for") | ||
fTLSPort = flag.Int("https-port", 9283, "port to listen on https for") | ||
fDir = flag.String("dir", "~/.puma-dev", "directory to watch for apps") | ||
|
@@ -110,18 +110,17 @@ func main() { | |
} | ||
}() | ||
|
||
stop := make(chan os.Signal, 1) | ||
|
||
signal.Notify(stop, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM) | ||
shutdown := make(chan os.Signal, 1) | ||
signal.Notify(shutdown, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM) | ||
|
||
go func() { | ||
<-stop | ||
<-shutdown | ||
fmt.Printf("! Shutdown requested\n") | ||
pool.Purge() | ||
os.Exit(0) | ||
}() | ||
|
||
err = dev.ConfigureResolver(domains, *fPort) | ||
err = dev.ConfigureResolver(domains, *fDNSPort) | ||
if err != nil { | ||
log.Fatalf("Unable to configure OS X resolver: %s", err) | ||
} | ||
|
@@ -133,7 +132,7 @@ func main() { | |
|
||
fmt.Printf("* Directory for apps: %s\n", dir) | ||
fmt.Printf("* Domains: %s\n", strings.Join(domains, ", ")) | ||
fmt.Printf("* DNS Server port: %d\n", *fPort) | ||
fmt.Printf("* DNS Server port: %d\n", *fDNSPort) | ||
|
||
if *fLaunch { | ||
fmt.Printf("* HTTP Server port: inherited from launchd\n") | ||
|
@@ -143,11 +142,12 @@ func main() { | |
fmt.Printf("* HTTPS Server port: %d\n", *fTLSPort) | ||
} | ||
|
||
var dns dev.DNSResponder | ||
|
||
dns.Address = fmt.Sprintf("127.0.0.1:%d", *fPort) | ||
|
||
go dns.Serve(domains) | ||
dns := dev.NewDNSResponder(fmt.Sprintf("127.0.0.1:%d", *fDNSPort), domains) | ||
go func() { | ||
if err := dns.Serve(); err != nil { | ||
fmt.Printf("! DNS Server failed: %v\n", err) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check the return of |
||
}() | ||
|
||
var http dev.HTTPServer | ||
|
||
|
@@ -169,12 +169,16 @@ func main() { | |
tlsSocketName = "SocketTLS" | ||
} | ||
|
||
fmt.Printf("! Puma dev listening on http and https\n") | ||
fmt.Printf("! Puma dev running...\n") | ||
|
||
go http.ServeTLS(tlsSocketName) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. check the return of |
||
}() | ||
|
||
err = http.Serve(socketName) | ||
if err != nil { | ||
log.Fatalf("Error listening: %s", err) | ||
log.Fatalf("! HTTP Server failed: %s", err) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: we're still not bailing if either https or dns fail to bind. this is the behavior we've had up until now, and it seems unnecessary to change it as part of this work. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"testing" | ||
|
||
"github.com/puma/puma-dev/homedir" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMainPumaDev_Darwin(t *testing.T) { | ||
appLinkDir := homedir.MustExpand("~/.gotest-macos-puma-dev") | ||
|
||
defer linkAllTestApps(t, appLinkDir)() | ||
|
||
configureAndBootPumaDevServer(t, map[string]string{ | ||
"dir": appLinkDir, | ||
"dns-port": "65053", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
"http-port": "65080", | ||
"https-port": "65443", | ||
}) | ||
|
||
runPlatformAgnosticTestScenarios(t) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
t.Run("resolve dns", func(t *testing.T) { | ||
PumaDevDNSDialer := func(ctx context.Context, network, address string) (net.Conn, error) { | ||
dnsAddress := fmt.Sprintf("127.0.0.1:%d", *fDNSPort) | ||
d := net.Dialer{} | ||
return d.DialContext(ctx, "udp", dnsAddress) | ||
} | ||
|
||
r := net.Resolver{ | ||
PreferGo: true, | ||
Dial: PumaDevDNSDialer, | ||
} | ||
|
||
ctx := context.Background() | ||
ips, err := r.LookupIPAddr(ctx, "foo.test") | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, net.ParseIP("127.0.0.1").To4(), ips[0].IP.To4()) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,6 @@ func main() { | |
pool.Events = &events | ||
|
||
purge := make(chan os.Signal, 1) | ||
|
||
signal.Notify(purge, syscall.SIGUSR1) | ||
|
||
go func() { | ||
|
@@ -73,12 +72,11 @@ func main() { | |
} | ||
}() | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. just a rename here. |
||
signal.Notify(shutdown, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM) | ||
|
||
go func() { | ||
<-stop | ||
<-shutdown | ||
fmt.Printf("! Shutdown requested\n") | ||
pool.Purge() | ||
os.Exit(0) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/puma/puma-dev/homedir" | ||
) | ||
|
||
func TestMainPumaDev_Linux(t *testing.T) { | ||
appLinkDir := homedir.MustExpand("~/.gotest-linux-puma-dev") | ||
|
||
defer linkAllTestApps(t, appLinkDir)() | ||
|
||
configureAndBootPumaDevServer(t, map[string]string{ | ||
"dir": appLinkDir, | ||
"http-port": "65080", | ||
"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.
this is only used in my fork, but high sierra is flaking a lot, so turning off for now.