diff --git a/src/Tests/IntegrationTests/TestBasic.cs b/src/Tests/IntegrationTests/TestBasic.cs index 8c3e269cb..8c5f02d00 100644 --- a/src/Tests/IntegrationTests/TestBasic.cs +++ b/src/Tests/IntegrationTests/TestBasic.cs @@ -33,7 +33,7 @@ public TestBasic(DefaultSuiteContext context) : base(context) { } [Fact] public void TestConnectedServer() { - using (NATSServer.CreateFastAndVerify()) + using (NATSServer.CreateFastAndVerifyQuietHandlers()) { using (var c = Context.OpenConnection()) { @@ -54,7 +54,7 @@ public void TestConnectedServer() [Fact] public void TestMultipleClose() { - using (NATSServer.CreateFastAndVerify()) + using (NATSServer.CreateFastAndVerifyQuietHandlers()) { using (var c = Context.OpenConnection()) { @@ -73,7 +73,7 @@ public void TestMultipleClose() [Fact] public void TestSimplePublish() { - using (NATSServer.CreateFastAndVerify()) + using (NATSServer.CreateFastAndVerifyQuietHandlers()) { using (IConnection c = Context.OpenConnection()) { @@ -85,7 +85,7 @@ public void TestSimplePublish() [Fact] public void TestSimplePublishNoData() { - using (NATSServer.CreateFastAndVerify()) + using (NATSServer.CreateFastAndVerifyQuietHandlers()) { using (IConnection c = Context.OpenConnection()) { @@ -109,7 +109,7 @@ public void TestSimplePublishNoData() [Fact] public void TestPublishDataWithOffsets() { - using (NATSServer.CreateFastAndVerify()) + using (NATSServer.CreateFastAndVerifyQuietHandlers()) { using (IConnection c = Context.OpenConnection()) { @@ -153,13 +153,13 @@ private bool compare(byte[] p1, byte[] p2) return true; } - private bool compare(byte[] payload, Msg m) + private bool Compare(byte[] payload, Msg m) { return compare(payload, m.Data); } // Compares a subset of expected (offset to count) against all of actual - private bool compare(byte[] expected, int offset, byte[] actual, int count) + private static bool compare(byte[] expected, int offset, byte[] actual, int count) { // null case if (expected == actual) @@ -251,12 +251,12 @@ public void TestSyncSubscribe() c.Publish("foo", omsg); Msg m = s.NextMessage(1000); - Assert.True(compare(omsg, m), "Messages are not equal."); + Assert.True(Compare(omsg, m), "Messages are not equal."); c.Publish("foo", omsg, 0, omsg.Length); m = s.NextMessage(1000); - Assert.True(compare(omsg, m), "Messages are not equal."); + Assert.True(Compare(omsg, m), "Messages are not equal."); c.Publish("foo", omsg, 2, 3); m = s.NextMessage(1000); @@ -279,12 +279,12 @@ public void TestPubWithReply() c.Publish("foo", "reply", omsg); Msg m = s.NextMessage(1000); - Assert.True(compare(omsg, m), "Messages are not equal."); + Assert.True(Compare(omsg, m), "Messages are not equal."); c.Publish("foo", "reply", omsg, 0, omsg.Length); m = s.NextMessage(1000); - Assert.True(compare(omsg, m), "Messages are not equal."); + Assert.True(Compare(omsg, m), "Messages are not equal."); c.Publish("foo", "reply", omsg, 1, 5); m = s.NextMessage(1000); @@ -2096,7 +2096,7 @@ public void TestMessageHeaderNoServerSupport() c.Publish(m); } } - + } // class } // namespace diff --git a/src/Tests/IntegrationTests/TestJetStreamManagement.cs b/src/Tests/IntegrationTests/TestJetStreamManagement.cs index 54e41ea0e..3db013946 100644 --- a/src/Tests/IntegrationTests/TestJetStreamManagement.cs +++ b/src/Tests/IntegrationTests/TestJetStreamManagement.cs @@ -14,12 +14,10 @@ using System; using System.Collections.Generic; using System.Text; -using System.Threading; using NATS.Client; using NATS.Client.Internals; using NATS.Client.JetStream; using Xunit; -using Xunit.Abstractions; using static IntegrationTests.JetStreamTestBase; using static UnitTests.TestBase; @@ -27,22 +25,13 @@ namespace IntegrationTests { public class TestJetStreamManagement : TestSuite { - private readonly ITestOutputHelper output; - - public TestJetStreamManagement(ITestOutputHelper output, JetStreamManagementSuiteContext context) : - base(context) - { - this.output = output; - Console.SetOut(new ConsoleWriter(output)); - } + public TestJetStreamManagement(JetStreamManagementSuiteContext context) : base(context) {} [Fact] public void TestStreamCreate() { Context.RunInJsServer(c => { - DateTime utcNow = DateTime.UtcNow; - IJetStreamManagement jsm = c.CreateJetStreamManagementContext(); StreamConfiguration sc = StreamConfiguration.Builder() @@ -52,8 +41,6 @@ public void TestStreamCreate() .Build(); StreamInfo si = jsm.AddStream(sc); - Assert.True(utcNow <= si.Created.ToUniversalTime()); - Assert.NotNull(si.Config); sc = si.Config; Assert.Equal(STREAM, sc.Name); @@ -91,8 +78,6 @@ public void TestStreamCreate() public void TestStreamCreateWithNoSubject() { Context.RunInJsServer(c => { - DateTime utcNow = DateTime.UtcNow; - IJetStreamManagement jsm = c.CreateJetStreamManagementContext(); StreamConfiguration sc = StreamConfiguration.Builder() @@ -101,8 +86,6 @@ public void TestStreamCreateWithNoSubject() { .Build(); StreamInfo si = jsm.AddStream(sc); - Assert.True(utcNow <= si.Created.ToUniversalTime()); - sc = si.Config; Assert.Equal(STREAM, sc.Name); @@ -228,10 +211,10 @@ public void TestAddUpdateStreamInvalids() Assert.Throws(() => jsm.UpdateStream(scMaxCon)); // cannot change RetentionPolicy - StreamConfiguration scReten = GetTestStreamConfigurationBuilder() + StreamConfiguration scRetention = GetTestStreamConfigurationBuilder() .WithRetentionPolicy(RetentionPolicy.Interest) .Build(); - Assert.Throws(() => jsm.UpdateStream(scReten)); + Assert.Throws(() => jsm.UpdateStream(scRetention)); }); } @@ -524,12 +507,12 @@ private void AssertInvalidConsumerUpdate(IJetStreamManagement jsm, ConsumerConfi private void AssertValidAddOrUpdate(IJetStreamManagement jsm, ConsumerConfiguration cc) { ConsumerInfo ci = jsm.AddOrUpdateConsumer(STREAM, cc); - ConsumerConfiguration cicc = ci.ConsumerConfiguration; + ConsumerConfiguration ciCc = ci.ConsumerConfiguration; Assert.Equal(cc.Durable, ci.Name); - Assert.Equal(cc.Durable, cicc.Durable); - Assert.Equal(cc.DeliverSubject, cicc.DeliverSubject); - Assert.Equal(cc.MaxDeliver, cicc.MaxDeliver); - Assert.Equal(cc.DeliverPolicy, cicc.DeliverPolicy); + Assert.Equal(cc.Durable, ciCc.Durable); + Assert.Equal(cc.DeliverSubject, ciCc.DeliverSubject); + Assert.Equal(cc.MaxDeliver, ciCc.MaxDeliver); + Assert.Equal(cc.DeliverPolicy, ciCc.DeliverPolicy); IList consumers = jsm.GetConsumerNames(STREAM); Assert.Single(consumers); @@ -670,10 +653,8 @@ public void TestDeleteMessage() { CreateDefaultTestStream(c); IJetStream js = c.CreateJetStreamContext(); - MsgHeader h = new MsgHeader(); - h.Add("foo", "bar"); + MsgHeader h = new MsgHeader { { "foo", "bar" } }; - DateTime beforeCreated = DateTime.UtcNow; //MessageInfo.Time is in UTC js.Publish(new Msg(SUBJECT, null, h, DataBytes(1))); js.Publish(new Msg(SUBJECT, null)); @@ -683,7 +664,6 @@ public void TestDeleteMessage() { Assert.Equal(SUBJECT, mi.Subject); Assert.Equal(Data(1), Encoding.ASCII.GetString(mi.Data)); Assert.Equal(1U, mi.Sequence); - Assert.True(SameOrAfter(mi.Time, beforeCreated)); Assert.NotNull(mi.Headers); Assert.Equal("bar", mi.Headers["foo"]); @@ -691,7 +671,6 @@ public void TestDeleteMessage() { Assert.Equal(SUBJECT, mi.Subject); Assert.Null(mi.Data); Assert.Equal(2U, mi.Sequence); - Assert.True(SameOrAfter(mi.Time, beforeCreated)); Assert.Null(mi.Headers); Assert.True(jsm.DeleteMessage(STREAM, 1, false)); // added coverage for use of erase (no_erase) flag. @@ -785,8 +764,8 @@ public void TestGetMessage() .WithSubjects(Subject(1), Subject(2)) .Build(); StreamInfo si = jsm.AddStream(sc); + Assert.False(si.Config.AllowDirect); - DateTime beforeCreated = DateTime.UtcNow; js.Publish(Subject(1), Encoding.UTF8.GetBytes("s1-q1")); js.Publish(Subject(2), Encoding.UTF8.GetBytes("s2-q2")); js.Publish(Subject(1), Encoding.UTF8.GetBytes("s1-q3")); @@ -794,37 +773,37 @@ public void TestGetMessage() js.Publish(Subject(1), Encoding.UTF8.GetBytes("s1-q5")); js.Publish(Subject(2), Encoding.UTF8.GetBytes("s2-q6")); - ValidateGetMessage(jsm, si, false, beforeCreated); + ValidateGetMessage(jsm); sc = StreamConfiguration.Builder(si.Config).WithAllowDirect(true).Build(); si = jsm.UpdateStream(sc); - ValidateGetMessage(jsm, si, true, beforeCreated); + Assert.True(si.Config.AllowDirect); + ValidateGetMessage(jsm); // error case stream doesn't exist Assert.Throws(() => jsm.GetMessage(Stream(999), 1)); }); } - private void ValidateGetMessage(IJetStreamManagement jsm, StreamInfo si, bool allowDirect, DateTime beforeCreated) { - Assert.Equal(allowDirect, si.Config.AllowDirect); + private void ValidateGetMessage(IJetStreamManagement jsm) { - AssertMessageInfo(1, 1, jsm.GetMessage(STREAM, 1), beforeCreated); - AssertMessageInfo(1, 5, jsm.GetLastMessage(STREAM, Subject(1)), beforeCreated); - AssertMessageInfo(2, 6, jsm.GetLastMessage(STREAM, Subject(2)), beforeCreated); + AssertMessageInfo(1, 1, jsm.GetMessage(STREAM, 1)); + AssertMessageInfo(1, 5, jsm.GetLastMessage(STREAM, Subject(1))); + AssertMessageInfo(2, 6, jsm.GetLastMessage(STREAM, Subject(2))); - AssertMessageInfo(1, 1, jsm.GetNextMessage(STREAM, 0, Subject(1)), beforeCreated); - AssertMessageInfo(2, 2, jsm.GetNextMessage(STREAM, 0, Subject(2)), beforeCreated); - AssertMessageInfo(1, 1, jsm.GetFirstMessage(STREAM, Subject(1)), beforeCreated); - AssertMessageInfo(2, 2, jsm.GetFirstMessage(STREAM, Subject(2)), beforeCreated); + AssertMessageInfo(1, 1, jsm.GetNextMessage(STREAM, 0, Subject(1))); + AssertMessageInfo(2, 2, jsm.GetNextMessage(STREAM, 0, Subject(2))); + AssertMessageInfo(1, 1, jsm.GetFirstMessage(STREAM, Subject(1))); + AssertMessageInfo(2, 2, jsm.GetFirstMessage(STREAM, Subject(2))); - AssertMessageInfo(1, 1, jsm.GetNextMessage(STREAM, 1, Subject(1)), beforeCreated); - AssertMessageInfo(2, 2, jsm.GetNextMessage(STREAM, 1, Subject(2)), beforeCreated); + AssertMessageInfo(1, 1, jsm.GetNextMessage(STREAM, 1, Subject(1))); + AssertMessageInfo(2, 2, jsm.GetNextMessage(STREAM, 1, Subject(2))); - AssertMessageInfo(1, 3, jsm.GetNextMessage(STREAM, 2, Subject(1)), beforeCreated); - AssertMessageInfo(2, 2, jsm.GetNextMessage(STREAM, 2, Subject(2)), beforeCreated); + AssertMessageInfo(1, 3, jsm.GetNextMessage(STREAM, 2, Subject(1))); + AssertMessageInfo(2, 2, jsm.GetNextMessage(STREAM, 2, Subject(2))); - AssertMessageInfo(1, 5, jsm.GetNextMessage(STREAM, 5, Subject(1)), beforeCreated); - AssertMessageInfo(2, 6, jsm.GetNextMessage(STREAM, 5, Subject(2)), beforeCreated); + AssertMessageInfo(1, 5, jsm.GetNextMessage(STREAM, 5, Subject(1))); + AssertMessageInfo(2, 6, jsm.GetNextMessage(STREAM, 5, Subject(2))); AssertStatus(10003, Assert.Throws(() => jsm.GetMessage(STREAM, 0))); AssertStatus(10037, Assert.Throws(() => jsm.GetMessage(STREAM, 9))); @@ -838,11 +817,10 @@ private void AssertStatus(int apiErrorCode, NATSJetStreamException e) { Assert.Equal(apiErrorCode, e.ApiErrorCode); } - private void AssertMessageInfo(int subj, ulong seq, MessageInfo mi, DateTime beforeCreated) { + private void AssertMessageInfo(int subj, ulong seq, MessageInfo mi) { Assert.Equal(STREAM, mi.Stream); Assert.Equal(Subject(subj), mi.Subject); Assert.Equal(seq, mi.Sequence); - Assert.True(SameOrAfter(mi.Time, beforeCreated)); Assert.Equal("s" + subj + "-q" + seq, Encoding.UTF8.GetString(mi.Data)); } diff --git a/src/Tests/IntegrationTests/TestUtilities.cs b/src/Tests/IntegrationTests/TestUtilities.cs index 8d05767d4..783198589 100644 --- a/src/Tests/IntegrationTests/TestUtilities.cs +++ b/src/Tests/IntegrationTests/TestUtilities.cs @@ -98,6 +98,20 @@ public static NATSServer CreateJetStreamFastAndVerify(int port, string args = nu public static NATSServer CreateFastAndVerify(string args = null) => CreateFastAndVerify(Defaults.Port, args); + public static NATSServer CreateFastAndVerifyQuietHandlers() + => CreateFastAndVerify(Defaults.Port, null, opts => + { + opts.ClosedEventHandler = (s, e) => { }; + opts.ServerDiscoveredEventHandler = (s, e) => { }; + opts.DisconnectedEventHandler = (s, e) => { }; + opts.ReconnectedEventHandler = (s, e) => { }; + opts.LameDuckModeEventHandler = (s, e) => { }; + opts.AsyncErrorEventHandler = (s, e) => { }; + opts.HeartbeatAlarmEventHandler = (s, e) => { }; + opts.UnhandledStatusEventHandler = (s, e) => { }; + opts.FlowControlProcessedEventHandler = (s, e) => { }; + }); + public static NATSServer CreateFastAndVerify(int port, string args = null, Action optionsModifier = null) { var server = new NATSServer(TimeSpan.Zero, port, args); diff --git a/src/Tests/UnitTests/TestBase.cs b/src/Tests/UnitTests/TestBase.cs index d221204f2..c286daf83 100644 --- a/src/Tests/UnitTests/TestBase.cs +++ b/src/Tests/UnitTests/TestBase.cs @@ -147,11 +147,5 @@ public static byte[] DataBytes() { public static byte[] DataBytes(int seq) { return Encoding.ASCII.GetBytes(Data(seq)); } - - public static bool Same(DateTime t1, DateTime t2) => t1.ToUniversalTime().CompareTo(t2.ToUniversalTime()) == 0; - public static bool Before(DateTime t1, DateTime t2) => t1.ToUniversalTime().CompareTo(t2.ToUniversalTime()) < 0; - public static bool After(DateTime t1, DateTime t2) => t1.ToUniversalTime().CompareTo(t2.ToUniversalTime()) > 0; - public static bool SameOrBefore(DateTime t1, DateTime t2) => t1.ToUniversalTime().CompareTo(t2.ToUniversalTime()) <= 0; - public static bool SameOrAfter(DateTime t1, DateTime t2) => t1.ToUniversalTime().CompareTo(t2.ToUniversalTime()) >= 0; - } -} \ No newline at end of file + } +}