Component test reference

Preparing a Component

Preparing a component: requirements, lifecycle, and commands

Verifier tests a component that already builds and runs. It does not need your source code — it needs a compiled interface model, a command that starts the component, and a transport and serializer both sides agree on.

This page covers what your component has to provide, how Verifier controls its lifecycle, and a complete first test from an empty directory.

What You Need

Five things. Verifier stops before sending anything if one is missing.

  • A compiled interface model. The JSON form of your Flex model, listed under flex_json_paths. It must declare your component, at least one peer, and at least one local protocol for your component. See verifier docs open model.
  • A command that starts your component. One entry under commands. It can be a binary, a Docker image, a Kubernetes pod, or a pair of start and stop commands Verifier triggers.
  • A transport both sides agree on. Verifier speaks the same wire mechanism your component speaks, on the same address and port. See verifier docs open transports.
  • A serializer both sides agree on. The serializer key sets how messages become bytes. A mismatch here produces a component that receives garbage and a Verifier that cannot decode replies.
  • A license file. Point license_file at the license bundle Tangram provided.

Run verifier doctor to check all five against your configuration before you run a test.

Lifecycle

Verifier owns your component’s process. It starts it, waits for it to come up, drives one attempt, and tears it down. The default is to do that around every attempt, so each attempt begins with a component in fresh state.

  • startup_ms: Required How long Verifier waits after starting the component before it begins sending. If your component sends a message first, Verifier treats it as up immediately and stops waiting.
  • shutdown_ms: Optional (Defaults to 0) How long Verifier waits after stopping the component before starting it again. Use this when your component needs time to release a port or a file.
  • restart: Optional (Defaults to true) When true, the component is started and torn down around each attempt. When false, it starts once at the beginning of an iteration and stays up for that whole iteration.

To tear a component down, Verifier sends SIGINT, then sleeps shutdown_ms.

capture_stdout and capture_stderr both default to true. Whatever your component writes to those streams is collected and logged when it exits, which is usually the fastest way to see why an attempt failed.

What This Means for Your Component

  • Be ready to receive within startup_ms. A component still binding its socket when Verifier sends its first message misses that message and the attempt fails. Raise startup_ms, or send a message on startup so Verifier proceeds as soon as you are ready.
  • Exit on SIGINT. A component that ignores it is killed and its ports may still be held when the next attempt starts. Set shutdown_ms high enough to cover your own cleanup.
  • Do not carry state between attempts. Each attempt is independent, and a restarting component is expected to come up the same way every time. If your component writes state to disk, clear it on startup or set restart: false and accept that every attempt in an iteration shares one process.
  • Start clean when restart: false. A long-lived component sees every attempt of every protocol in one process for the length of an iteration, including messages generated for protocols it is not currently being tested against.

Command Types

Four kinds of command entry. Pick the one that matches how your component runs. The full field list for each is in verifier docs open config.

Direct binary. Set command to the full command line, including arguments. Verifier launches it as a child process and manages it with signals. Use this when the component is an executable on the same machine.

commands:
  - command: /usr/local/bin/sensor --listen 6668 --report 6667
    startup_ms: 500

Docker container. Set image instead of command. Verifier runs and stops the container, and can set ports, environment, volumes, and host_network. Use this when the component ships as an image.

commands:
  - image: sensor:latest
    ports:
      - "6668:6668"
    startup_ms: 1000

Kubernetes pod. Set k8s_namespace and k8s_name. Kubernetes owns the pod; Verifier cycles it to control component lifetime. The pod must carry an app label matching k8s_name. Use this when the component already runs in a cluster.

commands:
  - k8s_namespace: default
    k8s_name: sensor
    startup_ms: 2000

External command. Set commandStart, commandKill, and commandWatch. Something else starts and stops the component; Verifier signals it by running your two commands, and watches the commandWatch file for modification to learn the component exited on its own. Use this when the component’s lifetime is managed by hardware, a test rig, or another orchestrator.

commands:
  - commandStart: /bin/bash -c 'echo start > /tmp/startfile'
    commandKill:  /bin/bash -c 'echo kill  > /tmp/killfile'
    commandWatch: /tmp/watchfile
    startup_ms: 1000
    shutdown_ms: 5000

You can list more than one command. They start in the order given, each waiting out its own startup_ms before the next begins.

A First Test, End to End

This walkthrough tests a component named Sensor that answers a request with a temperature report. Everything happens in one directory.

1. Write the model

Save this as sensor.flex. It declares two messages, the two components, and one protocol from Sensor’s point of view.

module example.sensor

annotation End(term: string)

message struct SampleRequest {
    id:     int32;
    window: uint32;
}

message struct SampleReport {
    id:      int32;
    celsius: float32;
}

component Sensor;
component Monitor;

@End("LastMessage")
local protocol sampleFlow in Sensor {
    recv let req: SampleRequest
        assuming req.window >= 1 && req.window <= 60
        from Monitor;

    send let rep: SampleReport
        where rep.id == req.id
           && rep.celsius >= -40.0 && rep.celsius <= 85.0
        to Monitor;
}

Sensor receives the request and sends the report, so Verifier does the opposite: it generates a SampleRequest with a window between 1 and 60, sends it, then waits for a SampleReport and checks that the identifier came back unchanged and the temperature is in range.

2. Compile the model

Verifier reads the compiled JSON form of a model, not the Flex source. Compile sensor.flex and save the output as sensor.json. For compiling models see docs.tangramflex.io.

3. Write the configuration

Save this as verifier.yaml. It uses two TCP transports: one Verifier connects out on to reach the component, one it binds so the component can reach it.

flex_json_paths:
  - ./sensor.json
component: example.sensor.Sensor
license_file: ./license.zip
serializer: direct
timeout_ms: 1000
iterations: 1
attempts: 3

commands:
  - command: /usr/local/bin/sensor --listen 6668 --report 6667
    startup_ms: 500
    shutdown_ms: 200

transports:
  - name: to_sensor
    type: tcp
    settings:
      type: Connect
      ip: 127.0.0.1
      port: 6668
      startup_ms: 100
  - name: from_sensor
    type: tcp
    settings:
      type: Bind
      ip: 127.0.0.1
      port: 6667
      startup_ms: 100

The model declares one connection in each direction, and each transport can carry traffic one way, so Verifier binds them by direction on its own. A Connect TCP transport can only send; a Bind TCP transport can only receive. When a model has several connections in the same direction, name them and list them under the transport’s connections key.

4. Check the setup

verifier doctor

Doctor reads the configuration and the model without starting your component, and reports what would fail. Fix every error before going further; warnings are worth reading but will not stop a run. Add --verbose to see the checks that passed as well.

5. Run the test

verifier run

Verifier starts your component, drives sampleFlow up to three times, prints a summary, and writes the full record to a timestamped directory under .verifier.

6. Read the results

verifier results

That prints the summary again from disk. To dig in:

verifier results prot sampleFlow
verifier results tui

And to gate an automated build on the outcome, which exits non-zero unless every protocol passed:

verifier results passed

Reading results in detail is covered in verifier docs open results.

Common Setup Failures

Verifier sends before the component is listening. The first message disappears and the protocol times out with nothing received. Raise startup_ms, or have your component publish something on startup so Verifier knows it is ready. If Verifier reports that not all commands started before timing out, the component never came up at all — check the captured output.

Topic mismatch. On a topic-routed transport, every message needs a topic, and it has to be the topic your component publishes and subscribes on. Verifier refuses to start when a message has no outgoing or incoming topic configured. Set the topic per message with @Topic in the model, or derive topics for all messages with the transport’s topic_map. If both sides have a topic but they do not match, your component receives nothing and Verifier receives nothing; compare the strings exactly, including case and separators.

Serializer mismatch. Your component receives bytes it cannot parse, or Verifier logs a decode failure on a message that did arrive. Both sides must use the same format. Set serializer to what your component actually uses, or set package_serializers when different packages on the wire use different formats.

Ambiguous component. When the model declares more than one component, Verifier cannot guess which one is under test and stops with a message listing the components it found. Set component to the fully-qualified name, for example example.sensor.Sensor.

A connection with no transport. Doctor reports a model connection not covered by any transport, or a configured connection with no match in the model. The names must agree: connection names in configuration are the fully-qualified Flex names, such as example.sensor.ControlIn. Check for a typo, or add a transport to carry the connection.

Missing or expired license. Verifier stops immediately. Point license_file at your license bundle, confirm the path is readable from where Verifier runs, and check the expiry date. A container that mounts the license at runtime still needs the path to be correct inside the container.

Wrong direction in the model. Every attempt fails at the first step, and the log shows Verifier waiting for a message your component is also waiting for. send and recv are written from your component’s point of view. See verifier docs open model.