Allow longer timeout for rollback
This commit is contained in:
parent
9779e9a367
commit
ad460465a5
@ -268,3 +268,42 @@ func TestHandler_ProxyAgentMapsLongRunningConfigCandidateApply(t *testing.T) {
|
||||
t.Fatalf("expected candidate apply response, got %s", rr.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandler_ProxyAgentMapsLongRunningRollback(t *testing.T) {
|
||||
agentServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
t.Fatalf("expected POST, got %s", r.Method)
|
||||
}
|
||||
if r.URL.Path != "/v1/media-server/rollback" {
|
||||
t.Fatalf("expected /v1/media-server/rollback, got %s", r.URL.Path)
|
||||
}
|
||||
time.Sleep(3500 * time.Millisecond)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"ok":true}`))
|
||||
}))
|
||||
defer agentServer.Close()
|
||||
|
||||
host, portText, err := net.SplitHostPort(strings.TrimPrefix(agentServer.URL, "http://"))
|
||||
if err != nil {
|
||||
t.Fatalf("parse test server address: %v", err)
|
||||
}
|
||||
port, err := strconv.Atoi(portText)
|
||||
if err != nil {
|
||||
t.Fatalf("parse test server port: %v", err)
|
||||
}
|
||||
|
||||
cfg := &config.Config{}
|
||||
agent := service.NewAgentClient(cfg)
|
||||
reg := service.NewRegistryService(cfg, agent)
|
||||
reg.UpdateDevice(&models.Device{DeviceID: "edge-01", IP: host, AgentPort: port})
|
||||
h := NewHandler(nil, reg, agent, nil, nil)
|
||||
|
||||
r := chi.NewRouter()
|
||||
r.Post("/api/devices/{id}/rollback", h.ProxyAgent)
|
||||
rr := httptest.NewRecorder()
|
||||
r.ServeHTTP(rr, httptest.NewRequest(http.MethodPost, "/api/devices/edge-01/rollback", nil))
|
||||
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Fatalf("expected status 200, got %d: %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,6 +104,9 @@ func isLongOp(method, path string) bool {
|
||||
if method == http.MethodPost && path == "/v1/config/candidate/apply" {
|
||||
return true
|
||||
}
|
||||
if method == http.MethodPost && path == "/v1/media-server/rollback" {
|
||||
return true
|
||||
}
|
||||
if strings.HasPrefix(path, "/v1/config/ui/") {
|
||||
return true
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user