-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #355 from matrix-org/dmr/cancel-ctx-on-conn-shutdown
- Loading branch information
Showing
7 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package syncv3_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"github.com/matrix-org/complement/client" | ||
"github.com/matrix-org/sliding-sync/sync3" | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
) | ||
|
||
func TestRequestCancelledWhenItsConnIsDestroyed(t *testing.T) { | ||
alice := registerNamedUser(t, "alice") | ||
|
||
t.Log("Alice does an initial sliding sync.") | ||
aliceRes := alice.SlidingSync(t, sync3.Request{}) | ||
|
||
t.Log("Alice prepares a second sliding sync request.") | ||
ctx := context.Background() | ||
req, err := http.NewRequestWithContext(ctx, "POST", proxyBaseURL+"/_matrix/client/unstable/org.matrix.msc3575/sync", nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
client.WithQueries(url.Values{ | ||
"timeout": []string{"1000"}, | ||
"pos": []string{aliceRes.Pos}, | ||
})(req) | ||
client.WithRawBody([]byte("{}")) | ||
client.WithContentType("application/json")(req) | ||
req.Header.Set("Authorization", "Bearer "+alice.AccessToken) | ||
|
||
done := make(chan struct{}) | ||
|
||
go func() { | ||
t.Log("Alice makes her second sync.") | ||
t.Log(req) | ||
_, err := alice.Client.Do(req) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
done <- struct{}{} | ||
}() | ||
|
||
t.Log("Alice logs out.") | ||
alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "logout"}) | ||
|
||
t.Log("Alice waits for her second sync response.") | ||
<-done | ||
|
||
if !errors.Is(ctx.Err(), context.Canceled) { | ||
t.Logf("ctx.Err(): got %v, expected %v", ctx.Err(), context.Canceled) | ||
} | ||
} |