DevOps build - Test execution hangs #198

Closed
opened 2025-12-29 14:24:53 +01:00 by adam · 5 comments
Owner

Originally created by @jorgeolive on GitHub (Aug 2, 2019).

Hello,

I know this issue is similar to #234, but anyway.

In an Azure DevOps pipeline apparently there's some issue when raising a mocked server in the remote agent. I have multiple XUnit tests where a WireMock server is used. When executing a test library, once first WireMock test is hit, test execution stops and no trace of exception is given. I have to stop the build process manually, otherwise it gets stuck there forever. This is how I am using it:

using (var server = FluentMockServer.Start())
            {
                var config = UnitTestDataGenerator.GetCorrectConfig(server.Ports[0]).ToList();
                config.AddRange(new List<Entity> { application, account, appdata, portalDoc, portalDocOld });
                fakedContext.Initialize(config);
                server.Given(
                        Request.Create().WithUrl("http://localhost:" + server.Ports[0] + /api").WithBody(body)
                            .UsingPost())
                    .RespondWith(
                        Response.Create()
                            .WithStatusCode(statuscode));

                //This is the actual happy path. Nothing should happen, no exception, nothing. 
                if (statuscode == 200)
                    fakedContext.ExecuteCodeActivity<GlobalUserBroadcastActivity>(inputs);

                if (statuscode != 200)
                {
                    var ex = Record.Exception(() =>
                        fakedContext.ExecuteCodeActivity<GlobalUserBroadcastActivity>(inputs));
                    Assert.IsType<InvalidPluginExecutionException>(ex);
                    Assert.Contains("HttpStatusCode", ex.Message);
                }

                server.Stop();
            }

I've tried to enclose the server.start() in a try / catch block without any different result. Any ideas? Am I doing anything wrong?

Originally created by @jorgeolive on GitHub (Aug 2, 2019). Hello, I know this issue is similar to #234, but anyway. In an Azure DevOps pipeline apparently there's some issue when raising a mocked server in the remote agent. I have multiple XUnit tests where a WireMock server is used. When executing a test library, once first WireMock test is hit, test execution stops and no trace of exception is given. I have to stop the build process manually, otherwise it gets stuck there forever. This is how I am using it: ``` c# using (var server = FluentMockServer.Start()) { var config = UnitTestDataGenerator.GetCorrectConfig(server.Ports[0]).ToList(); config.AddRange(new List<Entity> { application, account, appdata, portalDoc, portalDocOld }); fakedContext.Initialize(config); server.Given( Request.Create().WithUrl("http://localhost:" + server.Ports[0] + /api").WithBody(body) .UsingPost()) .RespondWith( Response.Create() .WithStatusCode(statuscode)); //This is the actual happy path. Nothing should happen, no exception, nothing. if (statuscode == 200) fakedContext.ExecuteCodeActivity<GlobalUserBroadcastActivity>(inputs); if (statuscode != 200) { var ex = Record.Exception(() => fakedContext.ExecuteCodeActivity<GlobalUserBroadcastActivity>(inputs)); Assert.IsType<InvalidPluginExecutionException>(ex); Assert.Contains("HttpStatusCode", ex.Message); } server.Stop(); } ``` I've tried to enclose the server.start() in a try / catch block without any different result. Any ideas? Am I doing anything wrong?
adam added the question label 2025-12-29 14:24:53 +01:00
adam closed this issue 2025-12-29 14:24:53 +01:00
Author
Owner

@StefH commented on GitHub (Aug 2, 2019):

  1. Use WithPath("/api")
  2. Did try to replace your code fakedContext.ExecuteCodeActivity with a simple call like new HttpClient().PostAsync(uri, form).GetAwaiter().GetResult(); ?
@StefH commented on GitHub (Aug 2, 2019): 1. Use `WithPath("/api")` 2. Did try to replace your code `fakedContext.ExecuteCodeActivity` with a simple call like `new HttpClient().PostAsync(uri, form).GetAwaiter().GetResult();` ?
Author
Owner

@jorgeolive commented on GitHub (Aug 2, 2019):

Well. I found that the problem is reproducible when I have multiple test classes using a WireMockServer. Seems that it's a problem of concurrency.

@jorgeolive commented on GitHub (Aug 2, 2019): Well. I found that the problem is reproducible when I have multiple test classes using a WireMockServer. Seems that it's a problem of concurrency.
Author
Owner

@StefH commented on GitHub (Aug 2, 2019):

The unit-tests for this project are also using xUnit.
Did you take a look at my unit-tests? Maybe there is a fundamental difference?

Or maybe it's related to sync - async ? (You need to define your unit-test as async in case you run async code...)

Is your project a public project ?

@StefH commented on GitHub (Aug 2, 2019): The unit-tests for this project are also using xUnit. Did you take a look at my unit-tests? Maybe there is a fundamental difference? Or maybe it's related to sync - async ? (You need to define your unit-test as async in case you run async code...) Is your project a public project ?
Author
Owner

@StefH commented on GitHub (Aug 16, 2019):

@jorgeolive Any update on your question?

@StefH commented on GitHub (Aug 16, 2019): @jorgeolive Any update on your question?
Author
Owner

@StefH commented on GitHub (Sep 23, 2019):

@jorgeolive Closing this issue.

If you still have a question, comment here or open a new one.

@StefH commented on GitHub (Sep 23, 2019): @jorgeolive Closing this issue. If you still have a question, comment here or open a new one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#198