Skip to content

Commit 28d30f0

Browse files
test(pubsub): new approach for CI
1 parent 066e74f commit 28d30f0

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

test/CoreApi/PubSubApiTest.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ public void Subscribed_Topics()
3737
// TODO: Assert.IsTrue(peers.Length > 0);
3838
}
3939

40+
volatile int messageCount = 0;
41+
4042
[TestMethod]
4143
public async Task Subscribe()
4244
{
43-
int messageCount = 0;
45+
messageCount = 0;
4446
var ipfs = TestFixture.Ipfs;
4547
var topic = "net-ipfs-api-test-" + Guid.NewGuid().ToString();
4648
await ipfs.PubSub.Subscribe(topic, msg =>
@@ -49,30 +51,37 @@ await ipfs.PubSub.Subscribe(topic, msg =>
4951
});
5052
await ipfs.PubSub.Publish(topic, "hello world!");
5153
await ipfs.PubSub.Publish(topic, "hello world!!");
52-
await Task.Delay(1000);
53-
Assert.AreEqual(2, messageCount);
54+
55+
while (messageCount != 2)
56+
{
57+
await Task.Delay(1000);
58+
}
5459
}
5560

61+
volatile int messageCount1 = 0;
62+
5663
[TestMethod]
5764
public async Task Unsubscribe()
5865
{
59-
int messageCount = 0;
66+
messageCount1 = 0;
6067
var ipfs = TestFixture.Ipfs;
6168
var topic = "net-ipfs-api-test-" + Guid.NewGuid().ToString();
6269
var cs = new CancellationTokenSource();
6370
await ipfs.PubSub.Subscribe(topic, msg =>
6471
{
65-
Interlocked.Increment(ref messageCount);
72+
Interlocked.Increment(ref messageCount1);
6673
}, cs.Token);
6774
await ipfs.PubSub.Publish(topic, "hello world!");
6875
await ipfs.PubSub.Publish(topic, "hello world!!");
69-
await Task.Delay(1000);
70-
Assert.AreEqual(2, messageCount);
76+
while (messageCount1 != 2)
77+
{
78+
await Task.Delay(1000);
79+
}
7180

7281
cs.Cancel();
7382
await ipfs.PubSub.Publish(topic, "hello world!!!");
74-
await Task.Delay(1000);
75-
Assert.AreEqual(2, messageCount);
83+
await Task.Delay(5000);
84+
Assert.AreEqual(2, messageCount1);
7685
}
7786
}
7887
}

0 commit comments

Comments
 (0)