コード例 #1
0
        public async Task SuccessiveRestarts_WorkerCountsStayTheSame()
        {
            int         expectedProcessCount = 3;
            List <Task> restartTasks         = new List <Task>();
            RpcFunctionInvocationDispatcher functionDispatcher = GetTestFunctionDispatcher(expectedProcessCount);
            await functionDispatcher.InitializeAsync(GetTestFunctionsList(RpcWorkerConstants.NodeLanguageWorkerName));

            await WaitForJobhostWorkerChannelsToStartup(functionDispatcher, expectedProcessCount);

            Guid[] invocationIds = new Guid[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
            List <TestRpcWorkerChannel> workerChannels = functionDispatcher.JobHostLanguageWorkerChannelManager.GetChannels().Cast <TestRpcWorkerChannel>().ToList();

            for (int i = 0; i < invocationIds.Length; ++i)
            {
                workerChannels[i % 3].SendInvocationRequest(new ScriptInvocationContext
                {
                    ExecutionContext = new ExecutionContext
                    {
                        InvocationId = invocationIds[i]
                    }
                });
            }

            foreach (var invocationId in invocationIds)
            {
                restartTasks.Add(functionDispatcher.RestartWorkerWithInvocationIdAsync(invocationId.ToString()));
            }
            await Task.WhenAll(restartTasks);

            Assert.Equal(expectedProcessCount, functionDispatcher.JobHostLanguageWorkerChannelManager.GetChannels().Count());   // Ensure count always stays at the initial count
        }
コード例 #2
0
        public async Task Restart_ParticularWorkerChannel_Succeeds_OnlyThatIsDisposed()
        {
            int expectedProcessCount = 3;
            RpcFunctionInvocationDispatcher functionDispatcher = GetTestFunctionDispatcher(expectedProcessCount);
            await functionDispatcher.InitializeAsync(GetTestFunctionsList(RpcWorkerConstants.NodeLanguageWorkerName));

            await WaitForJobhostWorkerChannelsToStartup(functionDispatcher, expectedProcessCount);

            Guid invocationId = Guid.NewGuid();
            List <TestRpcWorkerChannel> workerChannels = functionDispatcher.JobHostLanguageWorkerChannelManager.GetChannels().Cast <TestRpcWorkerChannel>().ToList();

            workerChannels[0].SendInvocationRequest(new ScriptInvocationContext
            {
                ExecutionContext = new ExecutionContext
                {
                    InvocationId = invocationId
                }
            });

            await functionDispatcher.RestartWorkerWithInvocationIdAsync(invocationId.ToString());

            Assert.True(workerChannels[0].IsDisposed);
            for (int i = 1; i < workerChannels.Count; ++i)
            {
                Assert.False(workerChannels[i].IsDisposed); // Ensure no other channel is disposed
            }

            Assert.Equal(expectedProcessCount, functionDispatcher.JobHostLanguageWorkerChannelManager.GetChannels().Count());   // Ensure count goes back to initial count
        }