Ejemplo n.º 1
0
        public async Task NodeProcess_Different_AfterHostRestart()
        {
            await SamplesTestHelpers.InvokeAndValidateHttpTrigger(_fixture, "HttpTrigger");

            IEnumerable <int> nodeProcessesBeforeHostRestart = Process.GetProcessesByName("node").Select(p => p.Id);
            // Trigger a restart
            await _fixture.Host.RestartAsync(CancellationToken.None);

            await SamplesTestHelpers.InvokeAndValidateHttpTrigger(_fixture, "HttpTrigger");

            // Wait for all the 3 process to start
            await Task.Delay(TimeSpan.FromMinutes(1));

            IEnumerable <int> nodeProcessesAfter = Process.GetProcessesByName("node").Select(p => p.Id);

            // Verify node process is different after host restart
            var result = nodeProcessesAfter.Where(pId1 => !nodeProcessesBeforeHostRestart.Any(pId2 => pId2 == pId1) && !_fixture.NodeProcessesBeforeTestStarted.Any(pId3 => pId3 == pId1));

            Assert.Equal(3, result.Count());
        }
Ejemplo n.º 2
0
        public async Task SetHostState_Offline_Succeeds()
        {
            string functionName = "HttpTrigger";

            // verify host is up and running
            var response = await GetHostStatusAsync();

            var hostStatus = response.Content.ReadAsAsync <HostStatus>();

            // verify functions can be invoked
            await SamplesTestHelpers.InvokeAndValidateHttpTrigger(_fixture, functionName);

            // verify function status is ok
            response = await GetFunctionStatusAsync(functionName);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            var functionStatus = await response.Content.ReadAsAsync <FunctionStatus>();

            Assert.Null(functionStatus.Errors);

            // take host offline
            await SetHostStateAsync("offline");

            // when testing taking the host offline doesn't seem to stop all
            // application services, so we issue a restart
            await RestartHostAsync();

            // wait for the host to go offline
            await AwaitHostStateAsync(ScriptHostState.Offline);

            // verify function status returns 503 immediately
            await TestHelpers.RunWithTimeoutAsync(async() =>
            {
                response = await GetFunctionStatusAsync(functionName);
            }, TimeSpan.FromSeconds(1));

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Null(functionStatus.Errors);

            // verify that when offline function requests return 503
            response = await SamplesTestHelpers.InvokeHttpTrigger(_fixture, functionName);
            await VerifyOfflineResponse(response);

            // verify that the root returns 503 immediately when offline
            var request = new HttpRequestMessage(HttpMethod.Get, string.Empty);

            response = await _fixture.Host.HttpClient.SendAsync(request);
            await VerifyOfflineResponse(response);

            // verify the same thing when invoking via admin api
            response = await AdminInvokeFunction(functionName);
            await VerifyOfflineResponse(response);

            // bring host back online
            await SetHostStateAsync("running");

            await AwaitHostStateAsync(ScriptHostState.Running);

            // need to reinitialize TestFunctionHost to reset IApplicationLifetime
            await _fixture.InitializeAsync();

            // verify functions can be invoked
            await SamplesTestHelpers.InvokeAndValidateHttpTrigger(_fixture, functionName);

            // verify the same thing via admin api
            response = await AdminInvokeFunction(functionName);

            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
        }
Ejemplo n.º 3
0
 public async Task HttpTrigger_Get_Succeeds()
 {
     await SamplesTestHelpers.InvokeAndValidateHttpTrigger(_fixture, "HttpTrigger");
 }