Find the bug
Can you find the bug in here?
public void Receiver(object ignored) { while (keepRunning) { using (var tx = new TransactionScope()) { Message msg; try { msg = receiver.Receive("uno", null, new TimeSpan(0, 0, 10)); } catch (TimeoutException) { continue; } catch(ObjectDisposedException) { continue; } lock (msgs) { msgs.Add(Encoding.ASCII.GetString(msg.Data)); Console.WriteLine(msgs.Count); } tx.Complete(); } } }
And:
[Fact] public void ShouldOnlyGetTwoItems() { ThreadPool.QueueUserWorkItem(Receiver); Sender(4); Sender(5); while(true) { lock (msgs) { if (msgs.Count>1) break; } Thread.Sleep(100); } Thread.Sleep(2000);//let it try to do something in addition to that receiver.Dispose(); keepRunning = false; Assert.Equal(2, msgs.Count); Assert.Equal("Message 4", msgs[0]); Assert.Equal("Message 5", msgs[1]); }
I will hint that you cannot make any part of the receiver after it was disposed.

Comments
Comment preview