Ejemplo n.º 1
0
        public async Task ShutdownDoesNotAbortCompilation()
        {
            var host = new TestableCompilerServerHost();

            using (var startedMre = new ManualResetEvent(initialState: false))
                using (var finishedMre = new ManualResetEvent(initialState: false))
                    using (var serverData = await ServerUtil.CreateServer(compilerServerHost: host))
                    {
                        // Create a compilation that is guaranteed to complete after the shutdown is seen.
                        host.RunCompilation = (request, cancellationToken) =>
                        {
                            startedMre.Set();
                            finishedMre.WaitOne();
                            return(s_emptyBuildResponse);
                        };

                        var compileTask = ServerUtil.Send(serverData.PipeName, s_emptyCSharpBuildRequest);
                        startedMre.WaitOne();

                        // The compilation is now in progress, send the shutdown.
                        await ServerUtil.SendShutdown(serverData.PipeName);

                        Assert.False(compileTask.IsCompleted);
                        finishedMre.Set();

                        var response = await compileTask;
                        Assert.Equal(BuildResponse.ResponseType.Completed, response.Type);
                        Assert.Equal(0, ((CompletedBuildResponse)response).ReturnCode);

                        await serverData.Verify(connections : 2, completed : 2);
                    }
        }
Ejemplo n.º 2
0
        public async Task IncorrectServerHashReturnsIncorrectHashResponse()
        {
            using (var serverData = await ServerUtil.CreateServer())
            {
                var buildResponse = await ServerUtil.Send(serverData.PipeName, new BuildRequest(BuildProtocolConstants.ProtocolVersion, RequestLanguage.CSharpCompile, "abc", new List <BuildRequest.Argument> {
                }));

                Assert.Equal(BuildResponse.ResponseType.IncorrectHash, buildResponse.Type);
            }
        }
Ejemplo n.º 3
0
        public async Task IncorrectProtocolReturnsMismatchedVersionResponse()
        {
            using (var serverData = await ServerUtil.CreateServer())
            {
                var buildResponse = await ServerUtil.Send(serverData.PipeName, new BuildRequest(1, RequestLanguage.CSharpCompile, "abc", new List <BuildRequest.Argument> {
                }));

                Assert.Equal(BuildResponse.ResponseType.MismatchedVersion, buildResponse.Type);
            }
        }
Ejemplo n.º 4
0
        public async Task RejectEmptyTempPath()
        {
            using var temp       = new TempRoot();
            using var serverData = await ServerUtil.CreateServer();

            var request  = BuildRequest.Create(RequestLanguage.CSharpCompile, workingDirectory: temp.CreateDirectory().Path, tempDirectory: null, BuildProtocolConstants.GetCommitHash(), libDirectory: null, args: Array.Empty <string>());
            var response = await ServerUtil.Send(serverData.PipeName, request);

            Assert.Equal(ResponseType.Rejected, response.Type);
        }
Ejemplo n.º 5
0
        public async Task CancelWillCancelCompilation()
        {
            var host = new TestableCompilerServerHost();

            using (var serverData = await ServerUtil.CreateServer(compilerServerHost: host))
                using (var mre = new ManualResetEvent(initialState: false))
                {
                    const int requestCount = 5;
                    var       count        = 0;

                    host.RunCompilation = (request, cancellationToken) =>
                    {
                        if (Interlocked.Increment(ref count) == requestCount)
                        {
                            mre.Set();
                        }

                        cancellationToken.WaitHandle.WaitOne();
                        return(new RejectedBuildResponse());
                    };

                    var list = new List <Task <BuildResponse> >();
                    for (var i = 0; i < requestCount; i++)
                    {
                        var task = ServerUtil.Send(serverData.PipeName, s_emptyCSharpBuildRequest);
                        list.Add(task);
                    }

                    // Wait until all of the connections are being processed by the server then cancel.
                    mre.WaitOne();
                    serverData.CancellationTokenSource.Cancel();

                    var stats = await serverData.Complete();

                    Assert.Equal(requestCount, stats.Connections);
                    Assert.Equal(requestCount, count);

                    foreach (var task in list)
                    {
                        var threw = false;
                        try
                        {
                            await task;
                        }
                        catch
                        {
                            threw = true;
                        }

                        Assert.True(threw);
                    }
                }
        }