Master

Testing a server without a client

The test calls the handler with a request value. No socket is opened, and the reason no socket is opened is the reason the test is fast enough to run on every deploy.

What you will see

One line. One test owns the transport, and the rest own the logic.

About 1 min of reading

Try It

Build a wrong request on purpose

1

Write the suite cases

printf 'ok 200\nmissing-field 400\ntoo-large 413\nunknown-route 404\n' > /tmp/s.txt; wc -l < /tmp/s.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
4. Four cases, and the four are the shape of the route.
2

Run the suite

printf 'pass 4 fail 0\n' | awk '{print ($3==0) ? "gate open" : "gate closed"}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
gate open. Zero failures is what lets the deploy happen.
3

Name the one transport test

printf 'transport=one_socket_test\n' > /tmp/t.txt; cat /tmp/t.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One line. One test owns the transport, and the rest own the logic.

Data Flow

A suite to a deploy gate
1 The test builds a request value
↓
2 The handler is called directly
↓
3 The response value is asserted
↓
4 The suite gates the deploy
Why this works
Why the suite is run on every deploy

The server is rebuilt often. A rebuild that is not tested is a rebuild that changed the contract silently.

The limit of a handler test

It does not test the pool or the drain. Those are tested under load, which is a different artefact.

Examples

The request is a value

The test builds it. A built request can be wrong on purpose in ways a client cannot express.

The response is a value

The test reads it. Reading a value is asserting on a field, and a field is a name.

The transport is tested once

One test opens a socket. The one test is the boundary, and the boundary is the whole transport.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← The project structure is the contract
Previous Lesson
The project structure is the contract
Next Lesson
Shipping a server that is bounded
Shipping a server that is bounded →