Skip to content

Commit

Permalink
Fixed flaky status changes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Jun 3, 2022
1 parent 2994795 commit 273028c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Test()
new StatusChangeRequest(evnt.Key, new[] {"A-1"}, "s4"),
new StatusChangeRequest(evnt.Key, new[] {"A-2"}, "s5")
});
WaitForStatusChanges(Client, evnt);
WaitForStatusChanges(Client, evnt, 5);

var statusChanges = Client.Events.StatusChangesForObject(evnt.Key, "A-1").All();

Expand Down
22 changes: 12 additions & 10 deletions SeatsioDotNet.Test/Events/ListStatusChangesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Test()
new StatusChangeRequest(evnt.Key, new[] {"A-2"}, "s2"),
new StatusChangeRequest(evnt.Key, new[] {"A-3"}, "s3"),
});
WaitForStatusChanges(Client, evnt);
WaitForStatusChanges(Client, evnt, 3);

var statusChanges = Client.Events.StatusChanges(evnt.Key).All();

Expand All @@ -33,8 +33,9 @@ public void PropertiesOfStatusChange()
var chartKey = CreateTestChart();
var evnt = Client.Events.Create(chartKey);
var extraData = new Dictionary<string, object> {{"foo", "bar"}};
Client.Events.ChangeObjectStatus(evnt.Key, new[] {new ObjectProperties("A-1", extraData)}, "s1", null, "order1");
WaitForStatusChanges(Client, evnt);
Client.Events.ChangeObjectStatus(evnt.Key, new[] {new ObjectProperties("A-1", extraData)}, "s1", null,
"order1");
WaitForStatusChanges(Client, evnt, 1);

var statusChanges = Client.Events.StatusChanges(evnt.Key).All();
var statusChange = statusChanges.First();
Expand All @@ -59,7 +60,7 @@ public void NotPresentOnChartAnymore()
var evnt = Client.Events.Create(chartKey, null, TableBookingConfig.AllByTable());
Client.Events.Book(evnt.Key, new[] {"T1"});
Client.Events.Update(evnt.Key, null, null, TableBookingConfig.AllBySeat());
WaitForStatusChanges(Client, evnt);
WaitForStatusChanges(Client, evnt, 1);

var statusChanges = Client.Events.StatusChanges(evnt.Key).All();
var statusChange = statusChanges.First();
Expand All @@ -80,7 +81,7 @@ public void Filter()
new StatusChangeRequest(evnt.Key, new[] {"B-1"}, "booked"),
new StatusChangeRequest(evnt.Key, new[] {"A-3"}, "booked")
});
WaitForStatusChanges(Client, evnt);
WaitForStatusChanges(Client, evnt, 4);

var statusChanges = Client.Events.StatusChanges(evnt.Key, filter: "A-").All();

Expand All @@ -99,7 +100,7 @@ public void SortAsc()
new StatusChangeRequest(evnt.Key, new[] {"B-1"}, "booked"),
new StatusChangeRequest(evnt.Key, new[] {"A-3"}, "booked")
});
WaitForStatusChanges(Client, evnt);
WaitForStatusChanges(Client, evnt, 4);

var statusChanges = Client.Events.StatusChanges(evnt.Key, sortField: "objectLabel").All();

Expand All @@ -118,7 +119,7 @@ public void SortAscPageBefore()
new StatusChangeRequest(evnt.Key, new[] {"B-1"}, "booked"),
new StatusChangeRequest(evnt.Key, new[] {"A-3"}, "booked")
});
WaitForStatusChanges(Client, evnt);
WaitForStatusChanges(Client, evnt, 4);

var statusChangeLister = Client.Events.StatusChanges(evnt.Key, sortField: "objectLabel");
var statusChangeA3 = statusChangeLister.All().ToList()[2];
Expand All @@ -139,7 +140,7 @@ public void SortAscPageAfter()
new StatusChangeRequest(evnt.Key, new[] {"B-1"}, "booked"),
new StatusChangeRequest(evnt.Key, new[] {"A-3"}, "booked")
});
WaitForStatusChanges(Client, evnt);
WaitForStatusChanges(Client, evnt, 4);

var statusChangeLister = Client.Events.StatusChanges(evnt.Key, sortField: "objectLabel");
var statusChangeA1 = statusChangeLister.All().ToList()[0];
Expand All @@ -160,9 +161,10 @@ public void SortDesc()
new StatusChangeRequest(evnt.Key, new[] {"B-1"}, "booked"),
new StatusChangeRequest(evnt.Key, new[] {"A-3"}, "booked")
});
WaitForStatusChanges(Client, evnt);
WaitForStatusChanges(Client, evnt, 4);

var statusChanges = Client.Events.StatusChanges(evnt.Key, sortField: "objectLabel", sortDirection: "DESC").All();
var statusChanges = Client.Events.StatusChanges(evnt.Key, sortField: "objectLabel", sortDirection: "DESC")
.All();

Assert.Equal(new[] {"B-1", "A-3", "A-2", "A-1"}, statusChanges.Select(s => s.ObjectLabel));
}
Expand Down
4 changes: 2 additions & 2 deletions SeatsioDotNet.Test/SeatsioClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ protected SeatsioClient CreateSeatsioClient(string secretKey, string workspaceKe
return new SeatsioClient(secretKey, workspaceKey, BaseUrl);
}

protected void WaitForStatusChanges(SeatsioClient client, Event evnt)
protected void WaitForStatusChanges(SeatsioClient client, Event evnt, int numStatusChanges)
{
var start = DateTimeOffset.Now;
while (true)
{
var statusChanges = client.Events.StatusChanges(evnt.Key).All();
if (statusChanges.ToList().Count == 0)
if (statusChanges.ToList().Count != numStatusChanges)
{
var duration = DateTimeOffset.Now.ToUnixTimeSeconds() - start.ToUnixTimeSeconds();
if (duration > 10)
Expand Down

0 comments on commit 273028c

Please sign in to comment.