From 647d3f375ab9033783bd07457f3f73e8a7e42349 Mon Sep 17 00:00:00 2001 From: moreal Date: Thu, 14 Sep 2023 20:25:10 +0900 Subject: [PATCH 1/3] Set tipChanged subject's buffer size to 1 --- NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs b/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs index 4fdf34bac..7ff4b2054 100644 --- a/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs +++ b/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs @@ -122,7 +122,7 @@ public PreloadStateType() private BlockHeader? _tipHeader; - private ISubject _subject = new ReplaySubject(); + private ISubject _subject = new ReplaySubject(1); private ISubject _transactionSubject = new Subject(); From 24c942423fb6a491a27b4bae96519585221b0b68 Mon Sep 17 00:00:00 2001 From: moreal Date: Fri, 15 Sep 2023 13:08:12 +0900 Subject: [PATCH 2/3] Correct tipChanged subscription test --- .../GraphTypes/StandaloneSubscriptionTest.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/NineChronicles.Headless.Tests/GraphTypes/StandaloneSubscriptionTest.cs b/NineChronicles.Headless.Tests/GraphTypes/StandaloneSubscriptionTest.cs index 76f309a1f..b45aa9f5a 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/StandaloneSubscriptionTest.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/StandaloneSubscriptionTest.cs @@ -53,14 +53,14 @@ public async Task SubscribeTipChangedEvent() lastCommit: GenerateBlockCommit(BlockChain.Tip.Index, BlockChain.Tip.Hash, GenesisValidators)); BlockChain.Append(block, GenerateBlockCommit(block.Index, block.Hash, GenesisValidators)); - var result = await ExecuteSubscriptionQueryAsync("subscription { tipChanged { index hash } }"); - // var data = (Dictionary)((ExecutionNode) result.Data!).ToValue()!; + + Assert.Equal(index, BlockChain.Tip.Index); + var result = await ExecuteSubscriptionQueryAsync("subscription { tipChanged { index hash } }"); Assert.IsType(result); var subscribeResult = (SubscriptionExecutionResult)result; - Assert.Equal(index, BlockChain.Tip.Index); var stream = subscribeResult.Streams!.Values.FirstOrDefault(); - var rawEvents = await stream.Take((int)index); + var rawEvents = await stream.Take(1); Assert.NotNull(rawEvents); var events = (Dictionary)((ExecutionNode)rawEvents.Data!).ToValue()!; From d69225211a18d9a854ad639d33aa5f1d7332df1c Mon Sep 17 00:00:00 2001 From: moreal Date: Mon, 18 Sep 2023 09:02:41 +0900 Subject: [PATCH 3/3] Wait 1 seocnd every loop in test --- .../GraphTypes/StandaloneSubscriptionTest.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NineChronicles.Headless.Tests/GraphTypes/StandaloneSubscriptionTest.cs b/NineChronicles.Headless.Tests/GraphTypes/StandaloneSubscriptionTest.cs index b45aa9f5a..27b8cec53 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/StandaloneSubscriptionTest.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/StandaloneSubscriptionTest.cs @@ -56,6 +56,8 @@ public async Task SubscribeTipChangedEvent() // var data = (Dictionary)((ExecutionNode) result.Data!).ToValue()!; Assert.Equal(index, BlockChain.Tip.Index); + await Task.Delay(TimeSpan.FromSeconds(1)); + var result = await ExecuteSubscriptionQueryAsync("subscription { tipChanged { index hash } }"); Assert.IsType(result); var subscribeResult = (SubscriptionExecutionResult)result;