public async Task BroadcastMessage(int count) { var seed = CreateTestSwarm(); seed.Start(); var swarms = new TestSwarm[count]; for (var i = 0; i < count; i++) { swarms[i] = CreateTestSwarm(); swarms[i].Start(); } try { foreach (var swarm in swarms) { await swarm.BootstrapAsync(new[] { seed.AsPeer }); } Log.Debug("Bootstrap completed."); seed.BroadcastTestMessage("foo"); Log.Debug("Broadcast completed."); var tasks = swarms.Select(swarm => swarm.WaitForTestMessageWithData("foo")); await Task.WhenAll(tasks); } finally { foreach (var swarm in swarms) { Assert.True(swarm.ReceivedTestMessageOfData("foo")); swarm.Stop(); } } }
public async Task RemoveDeadReplacementCache() { TestSwarm swarm = CreateTestSwarm(tableSize: 1, bucketSize: 1); TestSwarm swarmA = CreateTestSwarm(); TestSwarm swarmB = CreateTestSwarm(); TestSwarm swarmC = CreateTestSwarm(); swarm.Start(); swarmA.Start(); swarmB.Start(); swarmC.Start(); await swarmA.AddPeersAsync(new[] { swarm.AsPeer }, null); await swarmB.AddPeersAsync(new[] { swarm.AsPeer }, null); Assert.Single(swarm.Peers); Assert.Contains(swarmA.AsPeer, swarm.Peers); Assert.DoesNotContain(swarmB.AsPeer, swarm.Peers); swarmA.Stop(); swarmB.Stop(); await swarmC.AddPeersAsync(new[] { swarm.AsPeer }, null); await swarm.Protocol.RefreshTableAsync(TimeSpan.Zero, default(CancellationToken)); await swarm.Protocol.CheckReplacementCacheAsync(default(CancellationToken)); Assert.Single(swarm.Peers); Assert.DoesNotContain(swarmA.AsPeer, swarm.Peers); Assert.DoesNotContain(swarmB.AsPeer, swarm.Peers); Assert.Contains(swarmC.AsPeer, swarm.Peers); swarm.Stop(); swarmC.Stop(); swarm.Dispose(); }