Repository: microsoft/garnet
File: test/Garnet.test.cluster/ClusterManagementTests.cs (C#)

Code before:
        [Test, Order(4)]
        public async Task ClusterResetDisposesGossipConnections()
        {
            const string meetRecv = "meet_requests_recv";
            const string gossip = "gossip_success_count";

            var node_count = 3;
            context.CreateInstances(node_count, metricsSamplingFrequency: 1);
            context.CreateConnection();
            var endpoints = context.clusterTestUtils.GetEndpoints();
            for (int i = 0; i < endpoints.Length - 1; i++)
            {
                context.clusterTestUtils.Meet(i, i + 1, context.logger);
            }

            for (int i = 0; i < node_count; i++)
            {
                context.clusterTestUtils.WaitUntilNodeIsKnownByAllNodes(i);
            }

            context.clusterTestUtils.ClusterReset(0, soft: true);
            await Task.Delay(1000);

            // Let's compare and make sure there are no gossip messages coming in to the node that got reset.
            var server = context.clusterTestUtils.GetServer(0);
            var gossipsAfterReset = GetStat(server, "Stats", gossip);

            await Task.Delay(3000);
            var lateMeetAfterReset = GetStat(server, "Stats", meetRecv);
            var lateGossipsAfterReset = GetStat(server, "Stats", gossip);

            ClassicAssert.AreEqual(gossipsAfterReset, lateGossipsAfterReset, "Expected no new gossip messages after a reset.");

            ClassicAssert.AreEqual(1, context.clusterTestUtils.ClusterNodes(0).Nodes.Count(), "Expected the node to only know about itself after a reset.");
        }

        private string GetStat(IServer server, string section, string statName)
        {
            return server.Info(section).FirstOrDefault(x => x.Key == section)?.FirstOrDefault(x => x.Key == statName).Value;
        }

        [Test, Order(5)]
        public void ClusterKeySlotTest()
        {
            var node_count = 1;
            context.CreateInstances(node_count);
            context.CreateConnection();

            (string, int)[] testCases = [("6e6bzswz8}", 7038),
                ("8}jb94e7tf", 4828),
                ("{}2xc5pbb7", 11672),

Review comment (suggestion):
To avoid relying on the right timing below, maybe we can add field in gossipStats that returns number of open gossip connections. You can add this in ClusterProvider.cs:GetGossipStats. This way can be explicit that the connections have closed for this test. I am suprised that we didn't have this field before.

Code after:
        [Test, Order(4)]
        public async Task ClusterResetDisposesGossipConnections()
        {
            const string meetRecv = "meet_requests_recv";
            const string gossip = "gossip_success_count";

            var node_count = 3;
            context.CreateInstances(node_count, metricsSamplingFrequency: 1);
            context.CreateConnection();
            var endpoints = context.clusterTestUtils.GetEndpoints();
            for (int i = 0; i < endpoints.Length - 1; i++)
            {
                context.clusterTestUtils.Meet(i, i + 1, context.logger);
            }

            for (int i = 0; i < node_count; i++)
            {
                context.clusterTestUtils.WaitUntilNodeIsKnownByAllNodes(i);
            }

            await Task.Delay(1000);

            var server = context.clusterTestUtils.GetServer(0);
            var gossipConnections = GetStat(server, "Stats", "gossip_open_connections");
            ClassicAssert.AreEqual(node_count - 1, int.Parse(gossipConnections), "Expected one gossip connection per node.");

            context.clusterTestUtils.ClusterReset(0, soft: true);

            await Task.Delay(1000);

            gossipConnections = GetStat(server, "Stats", "gossip_open_connections");
            ClassicAssert.AreEqual("0", gossipConnections, "All gossip connections should be closed after a reset.");
            ClassicAssert.AreEqual(1, context.clusterTestUtils.ClusterNodes(0).Nodes.Count(), "Expected the node to only know about itself after a reset.");
        }

        private string GetStat(IServer server, string section, string statName)
        {
            return server.Info(section).FirstOrDefault(x => x.Key == section)?.FirstOrDefault(x => x.Key == statName).Value;
        }

        [Test, Order(5)]
        public void ClusterKeySlotTest()
        {
            var node_count = 1;
            context.CreateInstances(node_count);
            context.CreateConnection();

            (string, int)[] testCases = [("6e6bzswz8}", 7038),
                ("8}jb94e7tf", 4828),
                ("{}2xc5pbb7", 11672),
                ("vr{a07}pdt", 12154),