Skip to content

Commit 6f9e105

Browse files
authored
test: Improve event publishing test with timeout handling (#464)
Signed-off-by: André Silva <[email protected]>
1 parent 9030f8d commit 6f9e105

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

test/OpenFeature.Providers.GOFeatureFlag.Test/Services/EventPublisherTest.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,17 @@ public async Task PublishEventsAsync_ShouldSendEvents()
8181
Version = "1.0.0"
8282
};
8383
publisher.AddEvent(eventMock);
84-
await Task.Delay(TimeSpan.FromMilliseconds(500));
8584

85+
// Wait for the request to be made, with a timeout to prevent hanging
86+
var timeout = TimeSpan.FromSeconds(5);
87+
var startTime = DateTime.UtcNow;
88+
while (this._mockHttp.LastRequest == null && DateTime.UtcNow - startTime < timeout)
89+
{
90+
await Task.Delay(TimeSpan.FromMilliseconds(50));
91+
}
92+
93+
Assert.NotNull(this._mockHttp.LastRequest);
94+
Assert.NotNull(this._mockHttp.LastRequest.Content);
8695
var got = await this._mockHttp.LastRequest.Content.ReadAsStringAsync();
8796
var want =
8897
"{\"meta\": {},\"events\": [{\"kind\": \"feature\",\"defaultValue\": false,\"value\": \"toto\",\"variation\": \"on\",\"version\": \"1.0.0\",\"creationDate\": 1750406145,\"contextKind\": \"user\",\"key\": \"TEST\",\"userKey\": \"642e135a-1df9-4419-a3d3-3c42e0e67509\"}]}";

0 commit comments

Comments
 (0)