Skip to content

Commit

Permalink
Add ability to integration test per algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
dalibormesaric committed Oct 4, 2024
1 parent ae49a62 commit 03a5207
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions example/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ services:
environment:
- FE=localhost,example
- BE=example,http://172.17.0.1:8081,example,http://172.17.0.1:8082,example,http://172.17.0.1:8083
- ALGO=$ALGO
ports:
- "8080:8080"
- "8000:8000"
4 changes: 2 additions & 2 deletions internal/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ var (
Name: "rplb_backend_retries",
Help: "The total number of backend retries",
})
BackendHits = promauto.NewCounter(prometheus.CounterOpts{
BackendHits = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "rplb_backend_hits",
Help: "The total number of backend hits",
})
}, []string{"backend_name"})
)

func ListenAndServe(frontends frontend.Frontends, bp backend.BackendPool, messages chan interface{}, version string) {
Expand Down
2 changes: 1 addition & 1 deletion internal/reverseproxy/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (rp *reverseProxy) reverseProxyAndLoadBalance(w http.ResponseWriter, r *htt
tf := TrafficBackendFrame{TrafficFrame: &TrafficFrame{Type: "traffic-be", Name: liveBackend.Name, Hits: liveBackend.IncHits()}, FrontendName: host}
rp.messages <- tf
}
dashboard.BackendHits.Inc()
dashboard.BackendHits.WithLabelValues(liveBackend.URL.String()).Inc()
break
}

Expand Down
1 change: 1 addition & 0 deletions tests/.first.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALGO=first
8 changes: 5 additions & 3 deletions tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"sync"
"testing"
"time"

"github.com/dalibormesaric/rplb/internal/loadbalancing"
)

func TestIntegration(t *testing.T) {
SetUp()
setUp(loadbalancing.First)

var wg sync.WaitGroup

Expand All @@ -29,11 +31,11 @@ func TestIntegration(t *testing.T) {
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "rplb_backend_hits") {
if !strings.Contains(line, "rplb_backend_hits 10") {
if !strings.Contains(line, "rplb_backend_hits{backend_name=\"http://172.17.0.1:8081\"} 10") {
t.Error(line)
}
}
}

TearDown()
tearDown()
}
6 changes: 3 additions & 3 deletions tests/integration_utility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
)

func SetUp() {
func setUp(algo string) {
out, err := exec.Command("docker", "-v").Output()
if err != nil {
log.Fatalf("Docker not running: (%v)", err)
Expand All @@ -15,13 +15,13 @@ func SetUp() {
log.Fatal("Docker not running")
}

err = exec.Command("docker", "compose", "-f", "../example/compose.yaml", "up", "-d", "rplb").Run()
err = exec.Command("docker", "compose", "--env-file", "."+algo+".env", "-f", "../example/compose.yaml", "up", "-d", "rplb", "--build").Run()
if err != nil {
log.Fatal(err)
}
}

func TearDown() {
func tearDown() {
err := exec.Command("docker", "compose", "-f", "../example/compose.yaml", "down").Run()
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 03a5207

Please sign in to comment.