carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package activator
2
3import (
4 "bytes"
5 "github.com/carlosframework/platform/internal/registry"
6 "log"
7 "net/http/httptest"
8 "strings"
9 "testing"
10 "time"
11)
12
13func TestUnseededDiagnosticsStayBoundedWhileEveryRequestRefuses(t *testing.T) {
14 var logs bytes.Buffer
15 old := log.Writer()
16 log.SetOutput(&logs)
17 defer log.SetOutput(old)
18 now := time.Unix(100, 0)
19 a := &Service{now: func() time.Time { return now }}
20 rt := registry.Route{Host: "b.example"}
21 missing := &ServingFilesMissing{Incarnation: "inc-1"}
22 events, due := 0, 0
23 for i := 0; i < 100; i++ {
24 w := httptest.NewRecorder()
25 a.serveWakeError(w, httptest.NewRequest("GET", "/", nil), rt, missing)
26 if w.Code != 503 {
27 t.Fatal(w.Code)
28 }
29 if _, ok := a.wakeFailureEvent(&actEntry{host: rt.Host}, missing); ok {
30 events++
31 }
32 a.mu.Lock()
33 if a.allowFilesDiagnosticLocked(a.seedDiagnostics[rt.Host], "due") {
34 due++
35 }
36 a.mu.Unlock()
37 }
38 if events != 1 || due != 1 || strings.Count(logs.String(), "activator: wake") != 1 {
39 t.Fatal(events, due, logs.String())
40 }
41 now = now.Add(time.Minute)
42 if !a.allowFilesDiagnostic(rt.Host, missing, "http") {
43 t.Fatal("suppressed next interval")
44 }
45 if !a.allowFilesDiagnostic(rt.Host, &ServingFilesMissing{Incarnation: "inc-2"}, "http") {
46 t.Fatal("suppressed next incarnation")
47 }
48}
49