-1

I'm working on a couple of projects right now that could really use some mocking of third party services for our integration and performance tests. Normally, I would use WireMock-Net to spin up a quick service that can handle happy path and failure scenario's, simulate delays, etc., but, in these cases, I'm dealing tcp connections via ZeroMQ and websockets.

I'm looking for a framework that could accept or reject requests, create delays, maybe even proxy traffic for tcp communication based on some sort of mapping mechanism, very similar to wiremock. Ideally it would be in .Net, but, at the point where it's definitely open to different technologies, but would still want to be able to host in the cloud so that we can scale as needed for performance testing.

I dislike asking for a tool recommendation here, and would accept the question being closed if needed. Also cross posted this in a few other places (reddit, discord).

1 Answer 1

1

When it comes to mocking TCP communication for integration and performance tests, there are a few options you can consider. One popular framework that can handle TCP mocking is Mountebank. Mountebank is a versatile tool that supports creating mocks and stubs for various protocols, including TCP.

Here's a solution using Mountebank for mocking TCP communication:

  1. Install Mountebank:
  • Mountebank is a standalone executable that you can download from the official website (http://www.mbtest.org/) or install using package managers like npm (Node.js package manager).
  • Follow the installation instructions specific to your operating system.
  1. Create a TCP mock:
  • Start the Mountebank server by running the Mountebank executable.

  • Define the TCP mock configuration using a JSON file. Here's an example:

    { "port": 4545, "protocol": "tcp", "stubs": [ { "responses": [ { "is": { "data": "Mocked response" } } ] } ] }

This example defines a TCP mock that listens on port 4545 and responds with the message "Mocked response" when a request is received.

  • Save the configuration in a file, e.g., tcp-mock.json.
  1. Register the TCP mock:
  • Use the Mountebank API to register the TCP mock with the server. You can make a POST request to the Mountebank API endpoint /imposters and provide the TCP mock configuration JSON.

  • Here's an example using cURL:

    curl -X POST -d @tcp-mock.json http://localhost:2525/imposters

This command registers the TCP mock with the Mountebank server running on localhost:2525.

  1. Interact with the TCP mock:
  • Now, any client application that communicates with the specified TCP port (4545 in our example) will receive the mocked response ("Mocked response").
  • Configure your application or tests to connect to the Mountebank server's address and the TCP port specified in the mock configuration.

Mountebank provides additional features like request matching, response templating, and dynamic behavior, allowing you to simulate different scenarios and responses for your tests.

While Mountebank is primarily built on Node.js, it can be used with applications developed in various languages and hosted in the cloud for scalable performance testing.

Remember to adjust the TCP mock configuration according to your specific needs, including defining mappings for different request scenarios, delays, and proxying.

I hope this solution helps you mock TCP communication effectively for your integration and performance tests.

1
  • 1
    I'll be checking this out this week. If PoC seems to work, I'll mark as answered. Jun 26 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.