Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed Jun 22, 2023
1 parent 048a5ac commit 1d46a30
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
38 changes: 19 additions & 19 deletions sync3/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ func TestConn(t *testing.T) {
// initial request
resp, err := c.OnIncomingRequest(ctx, &Request{
pos: 0,
})
}, time.Now())
assertNoError(t, err)
assertPos(t, resp.Pos, 1)
assertInt(t, resp.Lists["a"].Count, 101)

// happy case, pos=1
resp, err = c.OnIncomingRequest(ctx, &Request{
pos: 1,
})
}, time.Now())
assertPos(t, resp.Pos, 2)
assertInt(t, resp.Lists["a"].Count, 102)
assertNoError(t, err)
// bogus position returns a 400
_, err = c.OnIncomingRequest(ctx, &Request{
pos: 31415,
})
}, time.Now())
if err == nil {
t.Fatalf("expected error, got none")
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestConnBlocking(t *testing.T) {
Sort: []string{"hi"},
},
},
})
}, time.Now())
}()
go func() {
defer wg.Done()
Expand All @@ -118,7 +118,7 @@ func TestConnBlocking(t *testing.T) {
Sort: []string{"hi2"},
},
},
})
}, time.Now())
}()
go func() {
wg.Wait()
Expand Down Expand Up @@ -148,18 +148,18 @@ func TestConnRetries(t *testing.T) {
},
}}, nil
}})
resp, err := c.OnIncomingRequest(ctx, &Request{})
resp, err := c.OnIncomingRequest(ctx, &Request{}, time.Now())
assertPos(t, resp.Pos, 1)
assertInt(t, resp.Lists["a"].Count, 20)
assertInt(t, callCount, 1)
assertNoError(t, err)
resp, err = c.OnIncomingRequest(ctx, &Request{pos: 1})
resp, err = c.OnIncomingRequest(ctx, &Request{pos: 1}, time.Now())
assertPos(t, resp.Pos, 2)
assertInt(t, resp.Lists["a"].Count, 20)
assertInt(t, callCount, 2)
assertNoError(t, err)
// retry! Shouldn't invoke handler again
resp, err = c.OnIncomingRequest(ctx, &Request{pos: 1})
resp, err = c.OnIncomingRequest(ctx, &Request{pos: 1}, time.Now())
assertPos(t, resp.Pos, 2)
assertInt(t, resp.Lists["a"].Count, 20)
assertInt(t, callCount, 2) // this doesn't increment
Expand All @@ -170,7 +170,7 @@ func TestConnRetries(t *testing.T) {
"a": {
Sort: []string{SortByName},
},
}})
}}, time.Now())
assertPos(t, resp.Pos, 2)
assertInt(t, resp.Lists["a"].Count, 20)
assertInt(t, callCount, 3) // this doesn't increment
Expand All @@ -191,25 +191,25 @@ func TestConnBufferRes(t *testing.T) {
},
}}, nil
}})
resp, err := c.OnIncomingRequest(ctx, &Request{})
resp, err := c.OnIncomingRequest(ctx, &Request{}, time.Now())
assertNoError(t, err)
assertPos(t, resp.Pos, 1)
assertInt(t, resp.Lists["a"].Count, 1)
assertInt(t, callCount, 1)
resp, err = c.OnIncomingRequest(ctx, &Request{pos: 1})
resp, err = c.OnIncomingRequest(ctx, &Request{pos: 1}, time.Now())
assertNoError(t, err)
assertPos(t, resp.Pos, 2)
assertInt(t, resp.Lists["a"].Count, 2)
assertInt(t, callCount, 2)
// retry with modified request data that shouldn't prompt data to be returned.
// should invoke handler again!
resp, err = c.OnIncomingRequest(ctx, &Request{pos: 1, UnsubscribeRooms: []string{"a"}})
resp, err = c.OnIncomingRequest(ctx, &Request{pos: 1, UnsubscribeRooms: []string{"a"}}, time.Now())
assertNoError(t, err)
assertPos(t, resp.Pos, 2)
assertInt(t, resp.Lists["a"].Count, 2)
assertInt(t, callCount, 3) // this DOES increment, the response is buffered and not returned yet.
// retry with same request body, so should NOT invoke handler again and return buffered response
resp, err = c.OnIncomingRequest(ctx, &Request{pos: 2, UnsubscribeRooms: []string{"a"}})
resp, err = c.OnIncomingRequest(ctx, &Request{pos: 2, UnsubscribeRooms: []string{"a"}}, time.Now())
assertNoError(t, err)
assertPos(t, resp.Pos, 3)
assertInt(t, resp.Lists["a"].Count, 3)
Expand All @@ -228,7 +228,7 @@ func TestConnErrors(t *testing.T) {

// random errors = 500
errCh <- errors.New("oops")
_, herr := c.OnIncomingRequest(ctx, &Request{})
_, herr := c.OnIncomingRequest(ctx, &Request{}, time.Now())
if herr.StatusCode != 500 {
t.Fatalf("random errors should be status 500, got %d", herr.StatusCode)
}
Expand All @@ -237,7 +237,7 @@ func TestConnErrors(t *testing.T) {
StatusCode: 400,
Err: errors.New("no way!"),
}
_, herr = c.OnIncomingRequest(ctx, &Request{})
_, herr = c.OnIncomingRequest(ctx, &Request{}, time.Now())
if herr.StatusCode != 400 {
t.Fatalf("expected status 400, got %d", herr.StatusCode)
}
Expand All @@ -258,7 +258,7 @@ func TestConnErrorsNoCache(t *testing.T) {
}
}})
// errors should not be cached
resp, herr := c.OnIncomingRequest(ctx, &Request{})
resp, herr := c.OnIncomingRequest(ctx, &Request{}, time.Now())
if herr != nil {
t.Fatalf("expected no error, got %+v", herr)
}
Expand All @@ -267,12 +267,12 @@ func TestConnErrorsNoCache(t *testing.T) {
StatusCode: 400,
Err: errors.New("no way!"),
}
_, herr = c.OnIncomingRequest(ctx, &Request{pos: resp.PosInt()})
_, herr = c.OnIncomingRequest(ctx, &Request{pos: resp.PosInt()}, time.Now())
if herr.StatusCode != 400 {
t.Fatalf("expected status 400, got %d", herr.StatusCode)
}
// but doing the exact same request should now work
_, herr = c.OnIncomingRequest(ctx, &Request{pos: resp.PosInt()})
_, herr = c.OnIncomingRequest(ctx, &Request{pos: resp.PosInt()}, time.Now())
if herr != nil {
t.Fatalf("expected no error, got %+v", herr)
}
Expand Down Expand Up @@ -361,7 +361,7 @@ func TestConnBufferRememberInflight(t *testing.T) {
var err *internal.HandlerError
for i, step := range steps {
t.Logf("Executing step %d", i)
resp, err = c.OnIncomingRequest(ctx, step.req)
resp, err = c.OnIncomingRequest(ctx, step.req, time.Now())
if !step.wantErr {
assertNoError(t, err)
}
Expand Down
32 changes: 16 additions & 16 deletions sync3/handler/connstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestConnStateInitial(t *testing.T) {
}
return result
}
cs := NewConnState(userID, deviceID, userCache, globalCache, &NopExtensionHandler{}, &NopJoinTracker{}, nil, 1000)
cs := NewConnState(userID, deviceID, userCache, globalCache, &NopExtensionHandler{}, &NopJoinTracker{}, nil, nil, 1000)
if userID != cs.UserID() {
t.Fatalf("UserID returned wrong value, got %v want %v", cs.UserID(), userID)
}
Expand All @@ -118,7 +118,7 @@ func TestConnStateInitial(t *testing.T) {
{0, 9},
}),
}},
}, false)
}, false, time.Now())
if err != nil {
t.Fatalf("OnIncomingRequest returned error : %s", err)
}
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestConnStateInitial(t *testing.T) {
{0, 9},
}),
}},
}, false)
}, false, time.Now())
if err != nil {
t.Fatalf("OnIncomingRequest returned error : %s", err)
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestConnStateInitial(t *testing.T) {
{0, 9},
}),
}},
}, false)
}, false, time.Now())
if err != nil {
t.Fatalf("OnIncomingRequest returned error : %s", err)
}
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestConnStateMultipleRanges(t *testing.T) {
userCache.LazyRoomDataOverride = mockLazyRoomOverride
dispatcher.Register(context.Background(), userCache.UserID, userCache)
dispatcher.Register(context.Background(), sync3.DispatcherAllUsers, globalCache)
cs := NewConnState(userID, deviceID, userCache, globalCache, &NopExtensionHandler{}, &NopJoinTracker{}, nil, 1000)
cs := NewConnState(userID, deviceID, userCache, globalCache, &NopExtensionHandler{}, &NopJoinTracker{}, nil, nil, 1000)

// request first page
res, err := cs.OnIncomingRequest(context.Background(), ConnID, &sync3.Request{
Expand All @@ -282,7 +282,7 @@ func TestConnStateMultipleRanges(t *testing.T) {
{0, 2},
}),
}},
}, false)
}, false, time.Now())
if err != nil {
t.Fatalf("OnIncomingRequest returned error : %s", err)
}
Expand All @@ -308,7 +308,7 @@ func TestConnStateMultipleRanges(t *testing.T) {
{0, 2}, {4, 6},
}),
}},
}, false)
}, false, time.Now())
if err != nil {
t.Fatalf("OnIncomingRequest returned error : %s", err)
}
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestConnStateMultipleRanges(t *testing.T) {
{0, 2}, {4, 6},
}),
}},
}, false)
}, false, time.Now())
if err != nil {
t.Fatalf("OnIncomingRequest returned error : %s", err)
}
Expand Down Expand Up @@ -383,7 +383,7 @@ func TestConnStateMultipleRanges(t *testing.T) {
{0, 2}, {4, 6},
}),
}},
}, false)
}, false, time.Now())
if err != nil {
t.Fatalf("OnIncomingRequest returned error : %s", err)
}
Expand Down Expand Up @@ -451,7 +451,7 @@ func TestBumpToOutsideRange(t *testing.T) {
userCache.LazyRoomDataOverride = mockLazyRoomOverride
dispatcher.Register(context.Background(), userCache.UserID, userCache)
dispatcher.Register(context.Background(), sync3.DispatcherAllUsers, globalCache)
cs := NewConnState(userID, deviceID, userCache, globalCache, &NopExtensionHandler{}, &NopJoinTracker{}, nil, 1000)
cs := NewConnState(userID, deviceID, userCache, globalCache, &NopExtensionHandler{}, &NopJoinTracker{}, nil, nil, 1000)
// Ask for A,B
res, err := cs.OnIncomingRequest(context.Background(), ConnID, &sync3.Request{
Lists: map[string]sync3.RequestList{"a": {
Expand All @@ -460,7 +460,7 @@ func TestBumpToOutsideRange(t *testing.T) {
{0, 1},
}),
}},
}, false)
}, false, time.Now())
if err != nil {
t.Fatalf("OnIncomingRequest returned error : %s", err)
}
Expand Down Expand Up @@ -495,7 +495,7 @@ func TestBumpToOutsideRange(t *testing.T) {
{0, 1},
}),
}},
}, false)
}, false, time.Now())
if err != nil {
t.Fatalf("OnIncomingRequest returned error : %s", err)
}
Expand Down Expand Up @@ -562,7 +562,7 @@ func TestConnStateRoomSubscriptions(t *testing.T) {
}
dispatcher.Register(context.Background(), userCache.UserID, userCache)
dispatcher.Register(context.Background(), sync3.DispatcherAllUsers, globalCache)
cs := NewConnState(userID, deviceID, userCache, globalCache, &NopExtensionHandler{}, &NopJoinTracker{}, nil, 1000)
cs := NewConnState(userID, deviceID, userCache, globalCache, &NopExtensionHandler{}, &NopJoinTracker{}, nil, nil, 1000)
// subscribe to room D
res, err := cs.OnIncomingRequest(context.Background(), ConnID, &sync3.Request{
RoomSubscriptions: map[string]sync3.RoomSubscription{
Expand All @@ -576,7 +576,7 @@ func TestConnStateRoomSubscriptions(t *testing.T) {
{0, 1},
}),
}},
}, false)
}, false, time.Now())
if err != nil {
t.Fatalf("OnIncomingRequest returned error : %s", err)
}
Expand Down Expand Up @@ -630,7 +630,7 @@ func TestConnStateRoomSubscriptions(t *testing.T) {
{0, 1},
}),
}},
}, false)
}, false, time.Now())
if err != nil {
t.Fatalf("OnIncomingRequest returned error : %s", err)
}
Expand Down Expand Up @@ -664,7 +664,7 @@ func TestConnStateRoomSubscriptions(t *testing.T) {
{0, 1},
}),
}},
}, false)
}, false, time.Now())
if err != nil {
t.Fatalf("OnIncomingRequest returned error : %s", err)
}
Expand Down

0 comments on commit 1d46a30

Please sign in to comment.