Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22.5
go-version: 1.24.0

- name: Build
run: go build

- name: Test
run: go test
run: go test -race
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.5 AS builder
FROM golang:1.24.0 AS builder
WORKDIR /build
# Separate dependency caching from compilation
COPY go.mod go.mod
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ It can be used to implement a control plane for a dynamic set of services, where
errors must be highlighted to the caller rather than ignored.

## Prerequisites
* go >= 1.22
* go >= 1.24
* OR docker

## Instructions
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module regproxy2

go 1.22.5
go 1.24.0

require (
github.com/google/uuid v1.6.0
Expand All @@ -16,4 +16,4 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
)
62 changes: 62 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,68 @@ func TestConcurrentRegister(t *testing.T) {
})
}

func TestConcurrentRegisterAndDeregister(t *testing.T) {
errorGroup, _ := errgroup.WithContext(t.Context())
errorGroupDeregister, _ := errgroup.WithContext(t.Context())

withRegProxy(t, func(url string, t *testing.T) {
created := make(chan string, 100)
for i := range 100 {
name := fmt.Sprintf("foo-%d", i)
request := fmt.Sprintf("{\"name\":\"%s\",\"callback\":\"baz\"}", name)
errorGroup.Go(func() error {
r, err := http.Post(url+"/register", "application/json", bytes.NewReader([]byte(request)))
if err != nil {
if i == 100 {
close(created)
}
return err
}
if r.StatusCode != 204 {
if i == 100 {
close(created)
}
return fmt.Errorf("Wrong status code from /register %d expected 204", r.StatusCode)
}
created <- name

if i == 100 {
close(created)
}
return nil
})
}

go func() {
for name := range created {
request := fmt.Sprintf("{\"name\":\"%s\"}", name)

errorGroupDeregister.Go(func() error {
r, err := http.Post(url+"/deregister", "application/json", bytes.NewReader([]byte(request)))
if err != nil {
return err
}
if r.StatusCode != 204 {
return fmt.Errorf("Wrong status code from /deregister %d expected 204", r.StatusCode)
}

return nil
})
}
}()

resultingError := errorGroup.Wait()
if resultingError != nil {
t.Fatal(resultingError)
}

resultingError = errorGroupDeregister.Wait()
if resultingError != nil {
t.Fatal(resultingError)
}
})
}

func register(url string, u registerRequest, t *testing.T) {
b, _ := json.Marshal(u)
r, err := http.Post(url+"/register", "application/json", bytes.NewReader(b))
Expand Down