|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Diagnostics; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading; |
| 7 | +using System.Threading.Tasks; |
| 8 | +using NetMQ.Sockets; |
| 9 | +using NUnit.Framework; |
| 10 | + |
| 11 | +namespace NetMQ.Tests |
| 12 | +{ |
| 13 | + [TestFixture] |
| 14 | + public class CleanupTests |
| 15 | + { |
| 16 | + [Test] |
| 17 | + public void Block() |
| 18 | + { |
| 19 | + const int count = 1000; |
| 20 | + |
| 21 | + NetMQConfig.Linger = TimeSpan.FromSeconds(0.5); |
| 22 | + |
| 23 | + using (var client = new DealerSocket(">tcp://localhost:5557")) |
| 24 | + { |
| 25 | + // Sending a lot of messages |
| 26 | + client.Options.SendHighWatermark = count; |
| 27 | + for (int i = 0; i < count; i++) |
| 28 | + { |
| 29 | + client.SendFrame("Hello"); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + Stopwatch stopwatch = Stopwatch.StartNew(); |
| 34 | + NetMQConfig.Cleanup(); |
| 35 | + stopwatch.Stop(); |
| 36 | + |
| 37 | + Assert.Greater(stopwatch.ElapsedMilliseconds, 500); |
| 38 | + } |
| 39 | + |
| 40 | + [Test] |
| 41 | + public void NoBlock() |
| 42 | + { |
| 43 | + const int count = 1000; |
| 44 | + |
| 45 | + NetMQConfig.Linger = TimeSpan.FromSeconds(0.5); |
| 46 | + |
| 47 | + using (var client = new DealerSocket(">tcp://localhost:5557")) |
| 48 | + { |
| 49 | + // Sending a lot of messages |
| 50 | + client.Options.SendHighWatermark = count; |
| 51 | + for (int i = 0; i < count; i++) |
| 52 | + { |
| 53 | + client.SendFrame("Hello"); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + Stopwatch stopwatch = Stopwatch.StartNew(); |
| 58 | + NetMQConfig.Cleanup(false); |
| 59 | + stopwatch.Stop(); |
| 60 | + |
| 61 | + Assert.Less(stopwatch.ElapsedMilliseconds, 500); |
| 62 | + } |
| 63 | + |
| 64 | + [Test] |
| 65 | + public void NoBlockNoDispose() |
| 66 | + { |
| 67 | + var client = new DealerSocket(">tcp://localhost:5557"); |
| 68 | + NetMQConfig.Cleanup(false); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments