fix: improve context handling in projections (#3638)

* fix: improve context handling in projections

* fix tests

* use as of system time for current sequence

* use as of system time for current sequence

Co-authored-by: Silvan <silvan.reusser@gmail.com>
This commit is contained in:
Livio Amstutz
2022-05-19 10:25:19 +02:00
committed by GitHub
parent ed0aa7088b
commit c71ccc8a80
7 changed files with 47 additions and 21 deletions

View File

@@ -138,7 +138,7 @@ func TestProjectionHandler_SearchQuery(t *testing.T) {
expectation(mock)
}
query, limit, err := h.SearchQuery()
query, limit, err := h.SearchQuery(context.Background())
if !tt.want.isErr(err) {
t.Errorf("ProjectionHandler.prepareBulkStmts() error = %v", err)
return
@@ -183,6 +183,13 @@ func TestStatementHandler_Update(t *testing.T) {
name: "begin fails",
args: args{
ctx: context.Background(),
stmts: []*handler.Statement{
NewNoOpStatement(&testEvent{
aggregateType: "agg",
sequence: 6,
previousSequence: 0,
}),
},
},
want: want{
expectations: []mockExpectation{
@@ -197,6 +204,13 @@ func TestStatementHandler_Update(t *testing.T) {
name: "current sequence fails",
args: args{
ctx: context.Background(),
stmts: []*handler.Statement{
NewNoOpStatement(&testEvent{
aggregateType: "agg",
sequence: 6,
previousSequence: 0,
}),
},
},
want: want{
expectations: []mockExpectation{
@@ -494,7 +508,7 @@ func TestStatementHandler_Update(t *testing.T) {
if !tt.want.isErr(err) {
t.Errorf("StatementHandler.Update() error = %v", err)
}
if tt.want.stmtsLen != len(stmts) {
if err == nil && tt.want.stmtsLen != len(stmts) {
t.Errorf("wrong stmts length: want: %d got %d", tt.want.stmtsLen, len(stmts))
}
@@ -1069,7 +1083,7 @@ func TestStatementHandler_executeStmts(t *testing.T) {
t.Fatalf("unexpected err in begin: %v", err)
}
idx := h.executeStmts(tx, tt.args.stmts, tt.args.sequences)
idx := h.executeStmts(tx, &tt.args.stmts, tt.args.sequences)
if idx != tt.want.idx {
t.Errorf("unexpected index want: %d got %d", tt.want.idx, idx)
}
@@ -1420,7 +1434,7 @@ func TestStatementHandler_currentSequence(t *testing.T) {
t.Fatalf("unexpected err in begin: %v", err)
}
seq, err := h.currentSequences(tx.Query)
seq, err := h.currentSequences(context.Background(), tx.QueryContext)
if !tt.want.isErr(err) {
t.Errorf("unexpected error: %v", err)
}