-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…n registrations that may produce exceptions when `CancellationTokenSource.Cancel()` is called. Basic idea here is to have the caller of `CancellationTokenSource.Cancel()` dispose of the `CancellationTokenRegistration` and have the message pump worker tasked with finishing the Awatier task continuations dispose of `CancellationTokenRegistration` when it's done via using statement.
- Loading branch information
Showing
5 changed files
with
96 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Newtonsoft.Json.Linq; | ||
using NUnit.Framework; | ||
using RethinkDb.Driver.Net; | ||
using static System.Console; | ||
using static RethinkDb.Driver.RethinkDB; | ||
|
||
namespace RethinkDb.Driver.Tests.GitHubIssues | ||
{ | ||
[TestFixture] | ||
public class Issue146 | ||
{ | ||
private Connection conn; | ||
|
||
[Test] | ||
public async Task Test() | ||
{ | ||
Print("Main Thread Start"); | ||
|
||
conn = R.Connection().Connect(); | ||
|
||
var cts = new CancellationTokenSource(); | ||
|
||
RunChanges(cts.Token); | ||
|
||
Print("Starting main thread delay."); | ||
await Task.Delay(500); | ||
|
||
Print($"Canceling task"); | ||
Action act = () => cts.Cancel(); | ||
|
||
act.ShouldNotThrow(); | ||
|
||
Print("End of main"); | ||
} | ||
|
||
private async void RunChanges(CancellationToken ct) | ||
{ | ||
Print("RunChanges: called"); | ||
Cursor<Model.Change<JObject>> changes = null; | ||
try | ||
{ | ||
Print("RunChanges: BEFORE Query"); | ||
changes = await R.Db("rethinkdb").Table("jobs") | ||
.Changes().OptArg("include_initial", "true") | ||
.RunChangesAsync<JObject>(conn, ct); | ||
Print("RunChanges: Have Cursor, iterating with MoveNextAsync."); | ||
while (await changes.MoveNextAsync(ct)) | ||
{ | ||
Print("RunChanges: got a change"); | ||
} | ||
} | ||
catch (OperationCanceledException ex) | ||
{ | ||
Print("RunChanges: op canceled"); | ||
} | ||
finally | ||
{ | ||
Print("RunChanges: finally"); | ||
changes?.Close(); | ||
Print("RunChanges: changes cursor closed"); | ||
} | ||
Print("RunChanges: returning"); | ||
} | ||
|
||
static void Print(string msg) | ||
{ | ||
WriteLine($">>> (TID:{Thread.CurrentThread.ManagedThreadId}): {msg}"); | ||
} | ||
} | ||
} |
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