mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
Simplify test case
This commit is contained in:
parent
18a781ab70
commit
c37e906bf5
@ -2,15 +2,12 @@ package syncv3_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/matrix-org/complement/client"
|
||||
"github.com/matrix-org/sliding-sync/sync3"
|
||||
"github.com/tidwall/gjson"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRequestCancelledWhenItsConnIsDestroyed(t *testing.T) {
|
||||
@ -26,60 +23,34 @@ func TestRequestCancelledWhenItsConnIsDestroyed(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
timeout := time.Second
|
||||
cancelWithin := 100 * time.Millisecond
|
||||
|
||||
client.WithQueries(url.Values{
|
||||
"timeout": []string{strconv.FormatInt(timeout.Milliseconds(), 10)},
|
||||
"timeout": []string{"1000"},
|
||||
"pos": []string{aliceRes.Pos},
|
||||
})(req)
|
||||
client.WithRawBody([]byte("{}"))
|
||||
client.WithContentType("application/json")(req)
|
||||
req.Header.Set("Authorization", "Bearer "+alice.AccessToken)
|
||||
|
||||
type secondSyncResponse struct {
|
||||
res *http.Response
|
||||
body gjson.Result
|
||||
duration time.Duration
|
||||
}
|
||||
done := make(chan secondSyncResponse)
|
||||
done := make(chan struct{})
|
||||
|
||||
go func() {
|
||||
t.Log("Alice makes her second sync.")
|
||||
t.Log(req)
|
||||
start := time.Now()
|
||||
res, err := alice.Client.Do(req)
|
||||
end := time.Now()
|
||||
|
||||
_, err := alice.Client.Do(req)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
done <- secondSyncResponse{
|
||||
res: res,
|
||||
body: gjson.ParseBytes(body),
|
||||
duration: end.Sub(start),
|
||||
}
|
||||
|
||||
done <- struct{}{}
|
||||
}()
|
||||
|
||||
t.Log("Alice logs out.")
|
||||
alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "logout"})
|
||||
|
||||
t.Log("Alice waits for her second sync to return.")
|
||||
response := <-done
|
||||
t.Log("Alice waits for her second sync response.")
|
||||
<-done
|
||||
|
||||
// TODO: At first I expected that this the cancelled request should return 400 M_UNKNOWN_POS.
|
||||
// But I think that is best handled on the next incoming request.
|
||||
// assertEqual(t, "status code", response.res.StatusCode, http.StatusBadRequest)
|
||||
// assertEqual(t, "response errcode", response.body.Get("errcode").Str, "M_UNKNOWN_POS")
|
||||
|
||||
if response.duration > cancelWithin {
|
||||
t.Errorf("Waited for %s, but expected second sync to cancel after at most %s", response.duration, cancelWithin)
|
||||
if !errors.Is(ctx.Err(), context.Canceled) {
|
||||
t.Logf("ctx.Err(): got %v, expected %v", ctx.Err(), context.Canceled)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user