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

print & log port bind failures, dns-related test coverage, test improvements #239

Merged
merged 10 commits into from
Apr 6, 2020
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ workflows:
version: 2
test:
jobs:
- test_high_sierra
# - test_high_sierra
Copy link
Member Author

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.

- test_mojave
- test_catalina

34 changes: 19 additions & 15 deletions cmd/puma-dev/main_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member Author

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

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")
Expand Down Expand Up @@ -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)
}
Expand All @@ -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")
Expand All @@ -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)
}
Copy link
Member Author

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

}()

var http dev.HTTPServer

Expand All @@ -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)
}
Copy link
Member Author

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

}()

err = http.Serve(socketName)
if err != nil {
log.Fatalf("Error listening: %s", err)
log.Fatalf("! HTTP Server failed: %s", err)
}
Copy link
Member Author

Choose a reason for hiding this comment

The 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.

}
46 changes: 46 additions & 0 deletions cmd/puma-dev/main_darwin_test.go
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",
Copy link
Member Author

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.

"http-port": "65080",
"https-port": "65443",
})

runPlatformAgnosticTestScenarios(t)
Copy link
Member Author

@nonrational nonrational Apr 3, 2020

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.


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())
})
}
8 changes: 3 additions & 5 deletions cmd/puma-dev/main_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func main() {
pool.Events = &events

purge := make(chan os.Signal, 1)

signal.Notify(purge, syscall.SIGUSR1)

go func() {
Expand All @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The 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)
Expand Down
21 changes: 21 additions & 0 deletions cmd/puma-dev/main_linux_test.go
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)
}
Loading