From 7fd64c0cc36d5ed731b855ac77098ec8d8dec2d6 Mon Sep 17 00:00:00 2001 From: xinchen Date: Sun, 20 Nov 2016 20:16:37 -0800 Subject: [PATCH] Add test for transport close during sasl negotiation. --- test/Common/ProtocolTests.cs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/test/Common/ProtocolTests.cs b/test/Common/ProtocolTests.cs index 0da12d8..0df417a 100644 --- a/test/Common/ProtocolTests.cs +++ b/test/Common/ProtocolTests.cs @@ -242,7 +242,7 @@ namespace Test.Amqp } [TestMethod] - public void InvalidSaslProtocolHeaderTest() + public void SaslInvalidProtocolHeaderTest() { Stream transport = null; @@ -292,6 +292,37 @@ namespace Test.Amqp }).Unwrap().GetAwaiter().GetResult(); } + [TestMethod] + public void SaslCloseTransportTest() + { + this.testListener.RegisterTarget(TestPoint.SaslInit, (stream, channel, fields) => + { + stream.Dispose(); + return TestOutcome.Stop; + }); + + Address myAddress = new Address("amqp://guest:@" + this.address.Host + ":" + this.address.Port); + Trace.WriteLine(TraceLevel.Information, "sync test"); + { + try + { + Connection connection = new Connection(myAddress); + Assert.IsTrue(false, "no exception was thrown 1"); + } + catch (ObjectDisposedException) { } + } + + Trace.WriteLine(TraceLevel.Information, "async test"); + Task.Factory.StartNew(async () => + { + try + { + Connection connection = await Connection.Factory.CreateAsync(myAddress); + } + catch (ObjectDisposedException) { } + }).Unwrap().GetAwaiter().GetResult(); + } + [TestMethod] public void SendWithInvalidRemoteChannelTest() {