NeverENG commented on code in PR #36:
URL: https://github.com/apache/dubbo-net/pull/36#discussion_r4596035545
##########
Tests/UnitTestForDubboNet/MyNacosTest.cs:
##########
@@ -104,6 +106,94 @@ await nacos.GetProvidersAsync(Service, Group),
}
}
+ [Fact]
+ public async Task
ProviderDiscovery_DisposeRemovesOnlyItsOwnNamingSubscription()
+ {
+ var server = new FakeNacos();
+ server.Add("1", 20880);
+ using MyNacos nacos = server.CreateClient();
+ int callsA = 0, callsB = 0;
+ using var first = new ProviderDiscovery(null!, nacos, Group, null!,
+ _ => { callsA++; return Task.CompletedTask; }, () => { });
+ using var second = new ProviderDiscovery(null!, nacos, Group, null!,
+ _ => { callsB++; return Task.CompletedTask; }, () => { });
+
+ Assert.Single((await
first.GetProviderEndPointsAsync(Service)).EndPoints);
+ Assert.Single((await
second.GetProviderEndPointsAsync(Service)).EndPoints);
+ Assert.Equal(1, server.NamingSubscribes);
+ await server.PushNaming();
+ Assert.Equal((1, 1), (callsA, callsB));
+
+ first.Dispose();
+ Assert.Single(server.NamingListeners);
+ await server.PushNaming();
+ Assert.Equal((1, 2), (callsA, callsB));
+ second.Dispose();
+ Assert.Empty(server.NamingListeners);
+ }
+
+ [Fact]
+ public async Task
ProviderDiscovery_CoalescesConcurrentLookupsAndDoesNotCacheTheResult()
+ {
+ var server = new FakeNacos();
+ server.Add("1", 20880);
+ server.InstanceGate = new TaskCompletionSource<List<Instance>>(
+ TaskCreationOptions.RunContinuationsAsynchronously);
+ using MyNacos nacos = server.CreateClient();
+ using var discovery = new ProviderDiscovery(null!, nacos, Group, null!,
+ _ => Task.CompletedTask, () => { });
+
+ Task<DubboServiceEndPointInfos>[] callers = Enumerable.Range(0, 32)
Review Comment:
已在 c98f0c4 修复这条测试的并发区分力:32 个调用改由独立 worker 同时等待栅栏,释放后进入
ProviderDiscovery.GetProviderEndPointsAsync;FakeNacos 在首个 SDK read 处暂停,让其他
worker 在 GetOrAdd 上竞争,再断言 InstanceReads == 1。完成后保留第二次查询得到 InstanceReads == 2
的“不缓存结果”断言。反事实验证:临时把 Lazy factory 改为提前启动 SDK 查询,该测试失败(1 failed);恢复 Lazy 后,net10
单测 633/633 通过,针对 netstandard2.0 库的 net10 单测也为 633/633。现有提交已推送到 PR #36;当前 head 的
GitHub CI 尚未报告结果,不将旧 head 的绿灯算作本次验证。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]