Skip to content

Commit

Permalink
Merge pull request #3363 from /issues/3328-golang-multiprocess-app
Browse files Browse the repository at this point in the history
Reimplement the multi-process test app with go
  • Loading branch information
georgethebeatle authored Jul 4, 2024
2 parents 2377911 + 05a4a3f commit 881430e
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 881430e

Please sign in to comment.