Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Utc times for integration tests #644

Merged
merged 5 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Tests/IntegrationTests/TestJetStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ public void TestConsumerIsNotModified()
.WithDeliverPolicy(DeliverPolicy.ByStartTime)
.WithDeliverSubject(Deliver(3))
.WithDurable(Durable(3))
.WithStartTime(DateTime.Now.AddHours(1))
.WithStartTime(DateTime.UtcNow.AddHours(1))
.Build();
jsm.AddOrUpdateConsumer(STREAM, cc);

Expand Down Expand Up @@ -677,7 +677,7 @@ public void TestSubscribeDurableConsumerMustMatch() {
ChangeExPush(js, PushDurableBuilder().WithFlowControl(10000), "FlowControl");
ChangeExPush(js, PushDurableBuilder().WithHeadersOnly(true), "HeadersOnly");

ChangeExPush(js, PushDurableBuilder().WithStartTime(DateTime.Now), "StartTime");
ChangeExPush(js, PushDurableBuilder().WithStartTime(DateTime.UtcNow), "StartTime");
ChangeExPush(js, PushDurableBuilder().WithAckWait(Duration.OfMillis(1)), "AckWait");
ChangeExPush(js, PushDurableBuilder().WithDescription("x"), "Description");
ChangeExPush(js, PushDurableBuilder().WithSampleFrequency("x"), "SampleFrequency");
Expand Down
14 changes: 7 additions & 7 deletions src/Tests/IntegrationTests/TestJetStreamManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void TestStreamCreate()
{
Context.RunInJsServer(c =>
{
DateTime now = DateTime.Now;
DateTime utcNow = DateTime.UtcNow;

IJetStreamManagement jsm = c.CreateJetStreamManagementContext();

Expand All @@ -42,7 +42,7 @@ public void TestStreamCreate()
.Build();

StreamInfo si = jsm.AddStream(sc);
Assert.True(now <= si.Created);
Assert.True(utcNow <= si.Created.ToUniversalTime());

Assert.NotNull(si.Config);
sc = si.Config;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void TestStreamCreate()
public void TestStreamCreateWithNoSubject() {
Context.RunInJsServer(c =>
{
DateTime now = DateTime.Now;
DateTime utcNow = DateTime.UtcNow;

IJetStreamManagement jsm = c.CreateJetStreamManagementContext();

Expand All @@ -91,7 +91,7 @@ public void TestStreamCreateWithNoSubject() {
.Build();

StreamInfo si = jsm.AddStream(sc);
Assert.True(now.CompareTo(si.Created) < 0);
Assert.True(utcNow <= si.Created.ToUniversalTime());

sc = si.Config;
Assert.Equal(STREAM, sc.Name);
Expand Down Expand Up @@ -639,7 +639,7 @@ public void TestGetAndDeleteMessage() {
MsgHeader h = new MsgHeader();
h.Add("foo", "bar");

DateTime beforeCreated = DateTime.Now;
DateTime beforeCreated = DateTime.UtcNow; //MessageInfo.Time is in UTC
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the comparison line 652, 660

js.Publish(new Msg(SUBJECT, null, h, DataBytes(1)));
js.Publish(new Msg(SUBJECT, null));

Expand All @@ -649,15 +649,15 @@ public void TestGetAndDeleteMessage() {
Assert.Equal(SUBJECT, mi.Subject);
Assert.Equal(Data(1), System.Text.Encoding.ASCII.GetString(mi.Data));
Assert.Equal(1U, mi.Sequence);
Assert.True(mi.Time >= beforeCreated);
Assert.True(mi.Time.ToUniversalTime() >= beforeCreated);
Assert.NotNull(mi.Headers);
Assert.Equal("bar", mi.Headers["foo"]);

mi = jsm.GetMessage(STREAM, 2);
Assert.Equal(SUBJECT, mi.Subject);
Assert.Null(mi.Data);
Assert.Equal(2U, mi.Sequence);
Assert.True(mi.Time >= beforeCreated);
Assert.True(mi.Time.ToUniversalTime() >= beforeCreated);
Assert.Null(mi.Headers);

Assert.True(jsm.DeleteMessage(STREAM, 1));
Expand Down
42 changes: 21 additions & 21 deletions src/Tests/IntegrationTests/TestKeyValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public TestKeyValue(ITestOutputHelper output, KeyValueSuiteContext context) : ba
}

[Fact]
public void TestWorkFLow()
public void TestWorkFlow()
{
DateTime now = DateTime.Now;
DateTime utcNow = DateTime.UtcNow;

string byteKey = "byteKey";
string stringKey = "stringKey";
Expand Down Expand Up @@ -117,13 +117,13 @@ public void TestWorkFLow()

// entry gives detail about latest entry of the key
byteHistory.Add(
AssertEntry(BUCKET, byteKey, KeyValueOperation.Put, 1, byteValue1, now, kv.Get(byteKey)));
AssertEntry(BUCKET, byteKey, KeyValueOperation.Put, 1, byteValue1, utcNow, kv.Get(byteKey)));

stringHistory.Add(
AssertEntry(BUCKET, stringKey, KeyValueOperation.Put, 2, stringValue1, now, kv.Get(stringKey)));
AssertEntry(BUCKET, stringKey, KeyValueOperation.Put, 2, stringValue1, utcNow, kv.Get(stringKey)));

longHistory.Add(
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 3, "1", now, kv.Get(longKey)));
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 3, "1", utcNow, kv.Get(longKey)));

// history gives detail about the key
AssertHistory(byteHistory, kv.History(byteKey));
Expand All @@ -139,7 +139,7 @@ public void TestWorkFLow()
kv.Delete(byteKey);

byteHistory.Add(
AssertEntry(BUCKET, byteKey, KeyValueOperation.Delete, 4, null, now, kv.Get(byteKey)));
AssertEntry(BUCKET, byteKey, KeyValueOperation.Delete, 4, null, utcNow, kv.Get(byteKey)));
AssertHistory(byteHistory, kv.History(byteKey));

// let's check the bucket info
Expand Down Expand Up @@ -170,15 +170,15 @@ public void TestWorkFLow()

// entry and history after update
byteHistory.Add(
AssertEntry(BUCKET, byteKey, KeyValueOperation.Put, 5, byteValue2, now, kv.Get(byteKey)));
AssertEntry(BUCKET, byteKey, KeyValueOperation.Put, 5, byteValue2, utcNow, kv.Get(byteKey)));
AssertHistory(byteHistory, kv.History(byteKey));

stringHistory.Add(
AssertEntry(BUCKET, stringKey, KeyValueOperation.Put, 6, stringValue2, now, kv.Get(stringKey)));
AssertEntry(BUCKET, stringKey, KeyValueOperation.Put, 6, stringValue2, utcNow, kv.Get(stringKey)));
AssertHistory(stringHistory, kv.History(stringKey));

longHistory.Add(
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 7, "2", now, kv.Get(longKey)));
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 7, "2", utcNow, kv.Get(longKey)));
AssertHistory(longHistory, kv.History(longKey));

// let's check the bucket info
Expand All @@ -192,7 +192,7 @@ public void TestWorkFLow()
Assert.Equal(3, lvalue);

longHistory.Add(
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 8, "3", now, kv.Get(longKey)));
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 8, "3", utcNow, kv.Get(longKey)));
AssertHistory(longHistory, kv.History(longKey));

status = kvm.GetBucketInfo(BUCKET);
Expand All @@ -208,7 +208,7 @@ public void TestWorkFLow()
// history only retains 3 records
longHistory.RemoveAt(0);
longHistory.Add(
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 9, "4", now, kv.Get(longKey)));
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 9, "4", utcNow, kv.Get(longKey)));
AssertHistory(longHistory, kv.History(longKey));

// record count does not increase
Expand All @@ -223,7 +223,7 @@ public void TestWorkFLow()
kv.Purge(longKey);
longHistory.Clear();
longHistory.Add(
AssertEntry(BUCKET, longKey, KeyValueOperation.Purge, 10, null, now, kv.Get(longKey)));
AssertEntry(BUCKET, longKey, KeyValueOperation.Purge, 10, null, utcNow, kv.Get(longKey)));
AssertHistory(longHistory, kv.History(longKey));

status = kvm.GetBucketInfo(BUCKET);
Expand All @@ -236,7 +236,7 @@ public void TestWorkFLow()
kv.Purge(byteKey);
byteHistory.Clear();
byteHistory.Add(
AssertEntry(BUCKET, byteKey, KeyValueOperation.Purge, 11, null, now, kv.Get(byteKey)));
AssertEntry(BUCKET, byteKey, KeyValueOperation.Purge, 11, null, utcNow, kv.Get(byteKey)));
AssertHistory(byteHistory, kv.History(byteKey));

status = kvm.GetBucketInfo(BUCKET);
Expand All @@ -249,7 +249,7 @@ public void TestWorkFLow()
kv.Purge(stringKey);
stringHistory.Clear();
stringHistory.Add(
AssertEntry(BUCKET, stringKey, KeyValueOperation.Purge, 12, null, now, kv.Get(stringKey)));
AssertEntry(BUCKET, stringKey, KeyValueOperation.Purge, 12, null, utcNow, kv.Get(stringKey)));
AssertHistory(stringHistory, kv.History(stringKey));

status = kvm.GetBucketInfo(BUCKET);
Expand All @@ -275,23 +275,23 @@ public void TestWorkFLow()
// put some more
Assert.Equal(13U, kv.Put(longKey, 110));
longHistory.Add(
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 13, "110", now, kv.Get(longKey)));
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 13, "110", utcNow, kv.Get(longKey)));

Assert.Equal(14U, kv.Put(longKey, 111));
longHistory.Add(
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 14, "111", now, kv.Get(longKey)));
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 14, "111", utcNow, kv.Get(longKey)));

Assert.Equal(15U, kv.Put(longKey, 112));
longHistory.Add(
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 15, "112", now, kv.Get(longKey)));
AssertEntry(BUCKET, longKey, KeyValueOperation.Put, 15, "112", utcNow, kv.Get(longKey)));

Assert.Equal(16U, kv.Put(stringKey, stringValue1));
stringHistory.Add(
AssertEntry(BUCKET, stringKey, KeyValueOperation.Put, 16, stringValue1, now, kv.Get(stringKey)));
AssertEntry(BUCKET, stringKey, KeyValueOperation.Put, 16, stringValue1, utcNow, kv.Get(stringKey)));

Assert.Equal(17U, kv.Put(stringKey, stringValue2));
stringHistory.Add(
AssertEntry(BUCKET, stringKey, KeyValueOperation.Put, 17, stringValue2, now, kv.Get(stringKey)));
AssertEntry(BUCKET, stringKey, KeyValueOperation.Put, 17, stringValue2, utcNow, kv.Get(stringKey)));

AssertHistory(longHistory, kv.History(longKey));
AssertHistory(stringHistory, kv.History(stringKey));
Expand Down Expand Up @@ -686,7 +686,7 @@ private void AssertHistory(IList<KeyValueEntry> manualHistory, IList<KeyValueEnt
}
}

private KeyValueEntry AssertEntry(string bucket, string key, KeyValueOperation op, ulong seq, string value, DateTime now, KeyValueEntry entry) {
private KeyValueEntry AssertEntry(string bucket, string key, KeyValueOperation op, ulong seq, string value, DateTime utcNow, KeyValueEntry entry) {
Assert.Equal(bucket, entry.Bucket);
Assert.Equal(key, entry.Key);
Assert.Equal(op, entry.Operation);
Expand All @@ -697,7 +697,7 @@ private KeyValueEntry AssertEntry(string bucket, string key, KeyValueOperation o
else {
Assert.Null(entry.Value);
}
Assert.True(now.CompareTo(entry.Created) < 0);
Assert.True(utcNow.CompareTo(entry.Created.ToUniversalTime()) < 0);
return entry;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tests/UnitTests/JetStream/TestConsumerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void ChangeFieldsIdentified()
AssertNotChange(ccTest, ccTest);
AssertChange(ccTest, orig, "FlowControl", "IdleHeartbeat");

ccTest = Builder(orig).WithStartTime(DateTime.Now).Build();
ccTest = Builder(orig).WithStartTime(DateTime.UtcNow).Build();
AssertNotChange(ccTest, ccTest);
AssertChange(ccTest, orig, "StartTime");

Expand Down
8 changes: 4 additions & 4 deletions src/Tests/UnitTests/JetStream/TestStreamConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public void TestExternal()
[Fact]
public void TestSource()
{
DateTime now = DateTime.Now;
DateTime now = DateTime.UtcNow;
Source s = new Source("name1", 1, now, "fs1", new External("api1", "deliver1"));
Assert.Equal("name1", s.Name);
Assert.Equal(1U, s.StartSeq);
Expand All @@ -295,7 +295,7 @@ public void TestSource()
Assert.Equal("api1", s.External.Api);
Assert.Equal("deliver1", s.External.Deliver);

now = DateTime.Now;
now = DateTime.UtcNow;
s = Source.Builder()
.WithName("name2")
.WithStartSeq(2)
Expand All @@ -318,7 +318,7 @@ public void TestSource()
[Fact]
public void TestMirror()
{
DateTime now = DateTime.Now;
DateTime now = DateTime.UtcNow;
Mirror m = new Mirror("name1", 1, now, "fs1", new External("api1", "deliver1"));
Assert.Equal("name1", m.Name);
Assert.Equal(1U, m.StartSeq);
Expand All @@ -327,7 +327,7 @@ public void TestMirror()
Assert.Equal("api1", m.External.Api);
Assert.Equal("deliver1", m.External.Deliver);

now = DateTime.Now;
now = DateTime.UtcNow;
m = Mirror.Builder()
.WithName("name2")
.WithStartSeq(2)
Expand Down