TCP Protocol

Any service that communicates over the TCP protocol is Testable.

When creating a new test scenario select Create Recording and use the following URL formats:

tcp://sample-streaming.testable.io:8091
tcps://someotherdns.com:9999

Example

Scripts

If you choose to define your scenario by writing a script you have access to the Node.js net and tls modules.

Recordings

Both HTTP and Web Sockets work over TCP of course, but they have special support in the Testable platform where we leverage protocol features such as:

  • Using HTTP Host header to indicate the MITM gateway key (i.e. http://{key}.gateway.testable.io)
  • Capturing the Content-Type of the response
  • Capturing the response code of the response

With raw TCP services there aren’t any headers, so we can’t use the Host header to tell the MITM gateway which service to route traffic to or into which recording to persist. While recording, each time a client opens a TCP socket to the MITM TCP gateway (i.e. {key} @ gateway.testable.io:8081) it must send the following UTF-8 encoded bytes first:

TestableGateway {key}\n

This tells the gateway which backend service and recording to use. Below is an example that utilizes the Testable Sample TCP Service which is accessible at tcp://sample-streaming.testable.io:8091. This is a simple echo service that writes back any data sent to it.

Recording

If you click on the connection the packets grid below will show you all the traffic sent/received over the connection (the Packets Grid also updates in real time).

Packets

To capture the traffic for the recording, we use the following Scala code:

import java.io.PrintStream
import java.net.Socket

object GatewayEchoTestClient extends App {
  val socket = new Socket("gateway.testable.io", 8081)
  val in = socket.getInputStream
  val out = new PrintStream(socket.getOutputStream)
  
  out.print("TestableGateway [gatewayKey]\nThis is some test data!")
  out.flush
  val data = new Array[Byte](100)
  in.read(data)

  println("Client received: " + new String(data))
  socket.close
}

Or the same in Javascript:

const net = require('net');

const socket = net.createConnection(8081, 'gateway.testable.io');
socket.on('connect', function() {
  console.log('Connection opened, writing message');
  socket.write('TestableGateway [gatewayKey]\nThis is some test data!');
});
socket.on('data', function(data) {
  console.log(`Received: ${data.toString()}`);
  socket.destroy();
});

Tests

During test execution the recorded steps will be replayed. The agent will use the received traffic from the server to decide how long to wait for incoming packets and whether or not the test succeeded.

Results

The platform captures a variety of stats for each TCP connection opened during test execution. Additional custom metrics can be added by first converting the recording into a script.