Skip to content

Commit

Permalink
Reimplement the multi-process test app with go
Browse files Browse the repository at this point in the history
The nodejs buildpack fails quite frequently due to connection errors
which causes annoying CI flakes. By reimplementing the multi-process
test app to use the binary buildpack we make the app push faster and
more reliable

fixes #3328

Co-authored-by: Danail Branekov <[email protected]>
  • Loading branch information
georgethebeatle and danail-branekov committed Jul 4, 2024
1 parent ed6ca31 commit 05a4a3f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
~/.*
*.test
tests/assets/dorifi/dorifi
tests/assets/multi-process/dorifi
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ test-smoke: build-dorifi

build-dorifi:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -C tests/assets/golang -o ../dorifi/dorifi .
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -C tests/assets/golang -o ../multi-process/dorifi .

GOFUMPT = $(shell go env GOPATH)/bin/gofumpt
install-gofumpt:
Expand Down
26 changes: 23 additions & 3 deletions tests/assets/golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@ import (
"path/filepath"
"strconv"
"strings"
"time"
)

const ServiceBindingRootEnv = "SERVICE_BINDING_ROOT"

func main() {
http.HandleFunc("/", helloWorldHandler)
arg := ""
if len(os.Args) > 1 {
arg = os.Args[1]
}

if arg != "" && arg != "web" {
for range time.Tick(time.Second * 1) {
fmt.Printf("Hello from %q\n", arg)
}

return
}

http.HandleFunc("/", helloWorldHandler(arg))
http.HandleFunc("/env.json", envJsonHandler)
http.HandleFunc("/servicebindingroot", serviceBindingRootHandler)
http.HandleFunc("/servicebindings", serviceBindingsHandler)
Expand Down Expand Up @@ -50,8 +64,14 @@ func exitHandler(w http.ResponseWriter, r *http.Request) {
os.Exit(exitCode)
}

func helloWorldHandler(w http.ResponseWriter, _ *http.Request) {
fmt.Fprintln(w, "Hi, I'm Dorifi!")
func helloWorldHandler(arg string) func(w http.ResponseWriter, _ *http.Request) {
return func(w http.ResponseWriter, _ *http.Request) {
if arg == "" {
fmt.Fprintln(w, "Hi, I'm Dorifi!")
} else {
fmt.Fprintf(w, "Hi, I'm Dorifi (%s)!\n", arg)
}
}
}

func envJsonHandler(w http.ResponseWriter, _ *http.Request) {
Expand Down
4 changes: 2 additions & 2 deletions tests/assets/multi-process/Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: node server.js
worker: node server.js worker
web: ./dorifi web
worker: ./dorifi worker
5 changes: 0 additions & 5 deletions tests/assets/multi-process/package.json

This file was deleted.

27 changes: 0 additions & 27 deletions tests/assets/multi-process/server.js

This file was deleted.

2 changes: 1 addition & 1 deletion tests/e2e/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ var _ = Describe("Apps", func() {
})

It("returns a different endpoint result", func() {
Eventually(func() []byte { return curlApp(appGUID, "") }).Should(ContainSubstring("Hello from a multi-process app!"))
Eventually(func() []byte { return curlApp(appGUID, "") }).Should(ContainSubstring("Hi, I'm Dorifi (web)!"))
})
})

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/multi_process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var _ = Describe("Multi Process", func() {
appGUID, _ = pushTestApp(spaceGUID, multiProcessAppBitsFile)
workerProcessGUID = getProcess(appGUID, "worker").GUID
body := curlApp(appGUID, "")
Expect(body).To(ContainSubstring("Hello from a multi-process app!"))
Expect(body).To(ContainSubstring("Hi, I'm Dorifi (web)!"))
})

AfterEach(func() {
Expand Down

0 comments on commit 05a4a3f

Please sign in to comment.