Skip to content

Commit

Permalink
test(Swarm): pending connections are canceled after StopAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed May 6, 2019
1 parent 3365bc0 commit 00b494c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/TaskWhenAnyResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static async Task<T> WhenAnyResult<T>(
}
running.Remove(winner);
}
cancel.ThrowIfCancellationRequested();
throw new AggregateException("No task(s) returned a result.", exceptions);
}
}
Expand Down
29 changes: 29 additions & 0 deletions test/SwarmTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,35 @@ public async Task Concurent_Connect_SameTask()
}
}

[TestMethod]
public async Task Connect_CancelsOnStop()
{
var swarm = new Swarm { LocalPeer = self };
var venus = new Peer
{
Id = "QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
Addresses = new MultiAddress[]
{
"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
}
};

await swarm.StartAsync();
var a = swarm.ConnectAsync(venus);
Assert.IsFalse(a.IsCanceled || a.IsFaulted);

await swarm.StopAsync();
var endTime = DateTime.Now.AddSeconds(3);
while (!a.IsCanceled && !a.IsFaulted)
{
if (DateTime.Now > endTime)
Assert.Fail("swarm did not cancel pending connection.");
await Task.Delay(100);
}
Assert.IsTrue(a.IsCanceled || a.IsFaulted);

}

[TestMethod]
public async Task Connect_WithSomeUnreachableAddresses()
{
Expand Down

0 comments on commit 00b494c

Please sign in to comment.