software steht so weit.
jetzt build + docker build und testen
This commit is contained in:
1 parent
42f0c0accb
commit
ca6cdcca63
90 files changed
+10298
-480
No files matched your search
@@ -331,3 +331,36 @@ func TestSleepCtx(t *testing.T) {
|
||||
t.Error("sleepCtx hat trotz Abbruch gewartet")
|
||||
}
|
||||
}
|
||||
|
||||
// OnConnect wird nach jedem erfolgreichen Verbindungsaufbau aufgerufen –
|
||||
// nicht bei Fehlantworten.
|
||||
func TestClient_OnConnect(t *testing.T) {
|
||||
var requests atomic.Int32
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if requests.Add(1)%2 == 1 {
|
||||
http.Error(w, "später", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
var connects, sleeps atomic.Int32
|
||||
c := &Client{
|
||||
URL: srv.URL,
|
||||
OnConnect: func() { connects.Add(1) },
|
||||
sleep: func(ctx context.Context, d time.Duration) error {
|
||||
if sleeps.Add(1) == 4 {
|
||||
cancel()
|
||||
return ctx.Err()
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
c.Run(ctx, func(Event) error { return nil })
|
||||
if n := connects.Load(); n != 2 {
|
||||
t.Errorf("OnConnect %d-mal, erwartet 2 (bei 4 Versuchen, davon 2 erfolgreich)", n)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user