Skip to content

Commit

Permalink
Make node addresses in quorum tests non-random
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Gera <[email protected]>
  • Loading branch information
matej-g committed Oct 24, 2022
1 parent ac81f1c commit 8c00361
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/receive/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"io"
"math"
"math/rand"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -416,6 +415,7 @@ func newTestHandlerHashring(appendables []*fakeAppendable, replicationFactor uin
},
}

ag := addrGen{}
for i := range appendables {
h := NewHandler(nil, &Options{
TenantHeader: DefaultTenantHeader,
Expand All @@ -427,7 +427,7 @@ func newTestHandlerHashring(appendables []*fakeAppendable, replicationFactor uin
})
handlers = append(handlers, h)
h.peers = peers
addr := randomAddr()
addr := ag.newAddr()
h.options.Endpoint = addr
cfg[0].Endpoints = append(cfg[0].Endpoints, h.options.Endpoint)
peers.cache[addr] = &fakeRemoteWriteGRPCServer{h: h}
Expand Down Expand Up @@ -1022,8 +1022,11 @@ func makeRequest(h *Handler, tenant string, wreq *prompb.WriteRequest) (*httptes
return rec, nil
}

func randomAddr() string {
return fmt.Sprintf("http://%d.%d.%d.%d:%d", rand.Intn(256), rand.Intn(256), rand.Intn(256), rand.Intn(256), rand.Intn(35000)+30000)
type addrGen struct{ n int }

func (a *addrGen) newAddr() string {
a.n++
return fmt.Sprintf("http://%d.%d.%d.%d:%d", a.n, a.n, a.n, a.n, 12345+a.n)
}

type fakeRemoteWriteGRPCServer struct {
Expand Down

0 comments on commit 8c00361

Please sign in to comment.