Crowdsec/decisions_stream bug fix (#1517)

* Fix bug when stream interval is greater or equal to 60s

Co-authored-by: alteredCoder <kevin@crowdsec.net>
This commit is contained in:
he2ss 2022-05-27 15:23:59 +02:00 committed by GitHub
parent 1fc9587919
commit e88e9946f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 28 deletions

View file

@ -2,6 +2,7 @@ package apiserver
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
@ -313,6 +314,8 @@ func TestStreamDecisionDedup(t *testing.T) {
// Create Valid Alert : 3 decisions for 127.0.0.1, longest has id=3
lapi.InsertAlertFromFile("./tests/alert_sample.json")
time.Sleep(2 * time.Second)
// Get Stream, we only get one decision (the longest one)
w := lapi.RecordResponse("GET", "/v1/decisions/stream?startup=true", emptyBody)
decisions, code, err := readDecisionsStreamResp(w)
@ -335,7 +338,6 @@ func TestStreamDecisionDedup(t *testing.T) {
assert.Equal(t, code, 200)
assert.Equal(t, len(decisions["deleted"]), 0)
assert.Equal(t, len(decisions["new"]), 0)
// We delete another decision, yet don't receive it in stream, since there's another decision on same IP
w = lapi.RecordResponse("DELETE", "/v1/decisions/2", emptyBody)
assert.Equal(t, 200, w.Code)