private async Task CheckRuntimeStatus(string instanceId, OrchestrationRuntimeStatus runtimeStatus, HttpStatusCode httpStatusCode = HttpStatusCode.OK)
        {
            var httpApiHandler = new HttpApiHandler(new DurableTaskExtensionMock()
            {
                NotificationUrl = new Uri(TestConstants.NotificationUrl)
            }, null);
            var httpResponseMessage = await httpApiHandler.WaitForCompletionOrCreateCheckStatusResponseAsync(
                new HttpRequestMessage
            {
                RequestUri = new Uri(TestConstants.RequestUri),
            },
                instanceId,
                new OrchestrationClientAttribute
            {
                TaskHub        = TestConstants.TaskHub,
                ConnectionName = TestConstants.ConnectionName,
            },
                TimeSpan.FromSeconds(30),
                TimeSpan.FromSeconds(8));

            Assert.Equal(httpResponseMessage.StatusCode, httpStatusCode);
            var content = await httpResponseMessage.Content.ReadAsStringAsync();

            var response = JsonConvert.DeserializeObject <JObject>(content);

            Assert.Equal(response["runtimeStatus"], runtimeStatus.ToString());
        }
        public async Task WaitForCompletionOrCreateCheckStatusResponseAsync_Returns_HTTP_200_Response_After_Few_Iterations()
        {
            var httpApiHandler = new HttpApiHandler(new DurableTaskExtensionMock()
            {
                NotificationUrl = new Uri(TestConstants.NotificationUrl)
            }, null);
            var stopwatch           = Stopwatch.StartNew();
            var httpResponseMessage = await httpApiHandler.WaitForCompletionOrCreateCheckStatusResponseAsync(
                new HttpRequestMessage
            {
                RequestUri = new Uri(TestConstants.RequestUri),
            },
                TestConstants.InstanceIdIterations,
                new OrchestrationClientAttribute
            {
                TaskHub        = TestConstants.TaskHub,
                ConnectionName = TestConstants.ConnectionName,
            },
                TimeSpan.FromSeconds(30),
                TimeSpan.FromSeconds(8));

            stopwatch.Stop();
            Assert.Equal(HttpStatusCode.OK, httpResponseMessage.StatusCode);
            var content = await httpResponseMessage.Content.ReadAsStringAsync();

            var value = JsonConvert.DeserializeObject <string>(content);

            Assert.Equal("Hello Tokyo!", value);
            Assert.True(stopwatch.Elapsed < TimeSpan.FromSeconds(30));
        }
        public async Task WaitForCompletionOrCreateCheckStatusResponseAsync_Returns_HTTP_200_Response()
        {
            var httpApiHandler = new HttpApiHandler(new DurableTaskExtensionMock()
            {
                NotificationUrl = new Uri(TestConstants.NotificationUrl)
            }, null);
            var httpResponseMessage = await httpApiHandler.WaitForCompletionOrCreateCheckStatusResponseAsync(
                new HttpRequestMessage
            {
                RequestUri = new Uri(TestConstants.RequestUri),
            },
                TestConstants.IntanceIdFactComplete,
                new OrchestrationClientAttribute
            {
                TaskHub        = TestConstants.TaskHub,
                ConnectionName = TestConstants.ConnectionName,
            },
                TimeSpan.FromSeconds(100),
                TimeSpan.FromSeconds(10));

            Assert.Equal(httpResponseMessage.StatusCode, HttpStatusCode.OK);
            var content = await httpResponseMessage.Content.ReadAsStringAsync();

            var value = JsonConvert.DeserializeObject <string>(content);

            Assert.Equal(value, "Hello Tokyo!");
        }
Exemplo n.º 4
0
        public async Task WaitForCompletionOrCreateCheckStatusResponseAsync_Throws_Exception_When_Bad_Timeout_Request()
        {
            var httpApiHandler = new HttpApiHandler(GetTestExtension(), null);
            var ex             = await Assert.ThrowsAsync <ArgumentException>(() => httpApiHandler.WaitForCompletionOrCreateCheckStatusResponseAsync(
                                                                                  new HttpRequestMessage
            {
                RequestUri = new Uri(TestConstants.RequestUri),
            },
                                                                                  TestConstants.InstanceId,
                                                                                  new OrchestrationClientAttribute
            {
                TaskHub        = TestConstants.TaskHub,
                ConnectionName = TestConstants.ConnectionName,
            },
                                                                                  TimeSpan.FromSeconds(0),
                                                                                  TimeSpan.FromSeconds(100)));

            Assert.Equal($"Total timeout 0 should be bigger than retry timeout 100", ex.Message);
        }
        public async Task WaitForCompletionOrCreateCheckStatusResponseAsync_Returns_HTTP_202_Response_After_Timeout()
        {
            var httpApiHandler = new HttpApiHandler(new DurableTaskExtensionMock()
            {
                NotificationUrl = new Uri(TestConstants.NotificationUrl)
            }, null);
            var stopWatch           = Stopwatch.StartNew();
            var httpResponseMessage = await httpApiHandler.WaitForCompletionOrCreateCheckStatusResponseAsync(
                new HttpRequestMessage
            {
                RequestUri = new Uri(TestConstants.RequestUri),
            },
                TestConstants.RandomInstanceId,
                new OrchestrationClientAttribute
            {
                TaskHub        = TestConstants.TaskHub,
                ConnectionName = TestConstants.ConnectionName,
            },
                TimeSpan.FromSeconds(100),
                TimeSpan.FromSeconds(10));

            stopWatch.Stop();
            Assert.Equal(HttpStatusCode.Accepted, httpResponseMessage.StatusCode);
            var content = await httpResponseMessage.Content.ReadAsStringAsync();

            var status = JsonConvert.DeserializeObject <JObject>(content);

            Assert.Equal(status["id"], TestConstants.RandomInstanceId);
            Assert.Equal(
                "http://localhost:7071/admin/extensions/DurableTaskExtension/instances/9b59154ae666471993659902ed0ba749?taskHub=SampleHubVS&connection=Storage&code=mykey",
                status["statusQueryGetUri"]);
            Assert.Equal(
                "http://localhost:7071/admin/extensions/DurableTaskExtension/instances/9b59154ae666471993659902ed0ba749/raiseEvent/{eventName}?taskHub=SampleHubVS&connection=Storage&code=mykey",
                status["sendEventPostUri"]);
            Assert.Equal(
                "http://localhost:7071/admin/extensions/DurableTaskExtension/instances/9b59154ae666471993659902ed0ba749/terminate?reason={text}&taskHub=SampleHubVS&connection=Storage&code=mykey",
                status["terminatePostUri"]);
            Assert.True(stopWatch.Elapsed > TimeSpan.FromSeconds(30));
        }