LogEntries not being recorded on subsequent tests #97

Closed
opened 2025-12-29 08:22:15 +01:00 by adam · 6 comments
Owner

Originally created by @tomwadley on GitHub (May 11, 2018).

Starting WireMock subsequent times on the same port with the same stubs appears to work, but the LogEntries are not recorded meaning you can't verify what was sent to the server.

    class Program
    {
        static async Task Main(string[] args)
        {
            await RunTest(); // prints "1"
            await RunTest(); // prints "0" for some reason
        }

        private static async Task RunTest()
        {
            var server = FluentMockServer.Start(9988);
            
            server.Given(Request.Create().WithPath("/").UsingGet())
                .RespondWith(Response.Create().WithStatusCode(200).WithBody("Hello"));
            
            Thread.Sleep(1000);

            var response = await new HttpClient().GetAsync("http://localhost:9988/");
            response.EnsureSuccessStatusCode();
            
            Console.WriteLine(server.LogEntries.Count());

            server.Stop();
        }
    }

I first noticed this using xunit in a Dotnet Core Web API project. The above is a simple reproduction using a console app.

EDIT: This is WireMock.Net 1.0.3.16 running on netcoreapp2.0

Originally created by @tomwadley on GitHub (May 11, 2018). Starting WireMock subsequent times on the same port with the same stubs appears to work, but the LogEntries are not recorded meaning you can't verify what was sent to the server. ``` class Program { static async Task Main(string[] args) { await RunTest(); // prints "1" await RunTest(); // prints "0" for some reason } private static async Task RunTest() { var server = FluentMockServer.Start(9988); server.Given(Request.Create().WithPath("/").UsingGet()) .RespondWith(Response.Create().WithStatusCode(200).WithBody("Hello")); Thread.Sleep(1000); var response = await new HttpClient().GetAsync("http://localhost:9988/"); response.EnsureSuccessStatusCode(); Console.WriteLine(server.LogEntries.Count()); server.Stop(); } } ``` I first noticed this using xunit in a Dotnet Core Web API project. The above is a simple reproduction using a console app. EDIT: This is WireMock.Net 1.0.3.16 running on netcoreapp2.0
adam closed this issue 2025-12-29 08:22:15 +01:00
Author
Owner

@StefH commented on GitHub (May 19, 2018):

Running on same port will indeed behave wrong, I think that the server is not really shutdown or that the OS does not yet release the port connection from client to server.

I've added a test with different ports, and that one is ok.
da46d300d7

So for now I would suggest not to use the same port, but always random.

@StefH commented on GitHub (May 19, 2018): Running on same port will indeed behave wrong, I think that the server is not really shutdown or that the OS does not yet release the port connection from client to server. I've added a test with different ports, and that one is ok. https://github.com/WireMock-Net/WireMock.Net/pull/142/commits/da46d300d72780f33ba951a874709bbb5f16c443 So for now I would suggest not to use the same port, but always random.
Author
Owner

@paulapaulTW commented on GitHub (May 28, 2018):

Recently merged pull request addresses this in .NET core; it was not an issue in full framework - 297743a19a

@paulapaulTW commented on GitHub (May 28, 2018): Recently merged pull request addresses this in .NET core; it was not an issue in full framework - https://github.com/WireMock-Net/WireMock.Net/commit/297743a19ad69984b84abe3e90c21aea15cb1989
Author
Owner

@cezarypiatekGC commented on GitHub (Jan 4, 2021):

Hi,

I'm still experiencing a similar problem. When I access the LogEntries collection the first time I'm getting no results. It looks like the LogEntries collection is not updated immediately because after adding await Task.Delay(3000); before, the problem disappears.

@cezarypiatekGC commented on GitHub (Jan 4, 2021): Hi, I'm still experiencing a similar problem. When I access the LogEntries collection the first time I'm getting no results. It looks like the LogEntries collection is not updated immediately because after adding `await Task.Delay(3000);` before, the problem disappears.
Author
Owner

@Zakashi92 commented on GitHub (Mar 29, 2023):

I'm having the same issue where log entries are coming back as empty, I'm running it on Linux version 4.15.0-202-generic.
Functional Test. Though it seems to be passing on Windows !

@Zakashi92 commented on GitHub (Mar 29, 2023): I'm having the same issue where log entries are coming back as empty, I'm running it on Linux version 4.15.0-202-generic. Functional Test. Though it seems to be passing on Windows !
Author
Owner

@Zakashi92 commented on GitHub (Mar 29, 2023):

I'm having the same issue where log entries are coming back as empty, I'm running it on Linux version 4.15.0-202-generic. Functional Test. Though it seems to be passing on Windows !

I have also tried removing random porting & I have tried with random porting both fail.

@Zakashi92 commented on GitHub (Mar 29, 2023): > I'm having the same issue where log entries are coming back as empty, I'm running it on Linux version 4.15.0-202-generic. Functional Test. Though it seems to be passing on Windows ! I have also tried removing random porting & I have tried with random porting both fail.
Author
Owner

@StefH commented on GitHub (Mar 29, 2023):

@Zakashi92
What version of .NET do you use?

@StefH commented on GitHub (Mar 29, 2023): @Zakashi92 What version of .NET do you use?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#97