Component tests
Components and local protocols
A component test checks that a component you’ve built does what its
Flex specification says. In your model, a component such as Radar has
local protocols: the conversation from its own point of view, which it
must follow whoever it’s talking to. ReportTemperature says
that Radar receives a ReadTemperature on
RequestChan, then sends back a Temperature
whose id matches the request’s.
The Verifier tests your component by playing everyone else. It starts your binary, sends it messages the local protocol allows, with values it generates, and checks every message the component sends back against the protocol, constraints included. A component that follows every one of its local protocols is conformant. One that sends the wrong message or a value that breaks a constraint, or never finishes a protocol, is non-conformant, and the Results page explains how to read why.
Where model checking proves the design, a component test checks the implementation, over the transport your component really speaks: TCP, UDP, ZeroMQ, or a message broker such as Kafka. The Verifier tests a component’s own local protocols, so give each component you test one. The Interface Model page describes what the Verifier reads from your model, including the annotations that control a test.
component Radar;
component CommandPost;
connection RequestChan from CommandPost to Radar;
connection ReplyChan from Radar to CommandPost;
message struct ReadTemperature { id: int32; }
message struct Temperature { id: int32; celsius: int32; }
local protocol ReportTemperature in Radar {
recv let req: ReadTemperature on RequestChan;
send let rep: Temperature
where rep.id == req.id
on ReplyChan;
}Test a component
tenon verify component tests a component you’ve built
against its Flex specification, using the Verifier. The Verifier starts
your binary, plays the other side of each of its local protocols over
the transport your component speaks, and checks every message it sends
back. The result is a verdict Tenon has checked itself:
conformant when the component followed every protocol,
and non-conformant when it didn’t.
Tenon tests the component in <dir>, or the current
folder, using its verifier.yaml. Before the test,
it checks your Flex sources, which are in <dir> too
unless you point --flex at them; a model that doesn’t check
fails straight away. Tenon then copies your binary and the other files
verifier.yaml names into a fresh working folder, and runs
the Verifier in Tenon’s image in Docker, or directly when you’re already
inside Tenon’s image in CI.
On a terminal you watch the Verifier’s progress as it runs, and the
verdict follows. --report also saves the results as
results.json, an HTML page and JUnit files, and
--json prints results.json instead of the
summary. Tenon keeps the Verifier’s own logs from every run for reading later, and you can see what a run
would do, without running it, with --dry-run.
A component that talks through a message broker needs one running for
its test. With the managed profile, Tenon starts the
services its env.toml
declares on a private Docker network, waits until they’re ready, and
removes them afterwards. See Test a
component over a message broker.
Tenon never builds your component, so build it before you test it. Docker must be running for a test on your machine.
Command:
tenon verify component [<dir>] [options]
Arguments
<dir>-
The component folder, with
verifier.yamlin it. Defaults to the current folder.
Options
--profile <attach|managed>-
How much Tenon sets up:
attachruns only the Verifier, against a component and any brokers already there, andmanagedalso starts the servicesenv.tomldeclares, then stops them. Defaults toprofileinenv.toml, elsemanagedifenv.tomldeclares services, elseattach. --vconfig <file>-
The Verifier’s configuration, from
<dir>. Defaults tovconfiginenv.toml, elseverifier.yaml. --flex <path>-
Your Flex sources, from
<dir>. Defaults to<dir>. --network <name>-
An existing Docker network for the Verifier to join.
attachonly. --signals <volume|dir>-
A Docker volume or folder that the Verifier shares with a component it
controls through signal files.
attachonly. --stage <file>-
Copy another file into the run. Repeat it for several. Files
verifier.yamlnames by a local path are copied for you. --report <dir>-
Also save
results.json,results.htmlandjunit/in<dir>. --json-
Print the Verifier’s
results.jsoninstead of the summary. --dry-run- Show what the run would do: the image, the network, the files it copies and the configuration changes it makes. Runs nothing, and needs no license seat.
--keep-workdir- Keep the run’s working folder after a run that passes. It’s always kept after a failure.
Exit codes
| Code | Meaning |
|---|---|
0 |
Conformant |
1 |
Non-conformant, or the model doesn’t check |
3 |
The model uses something component tests don’t support |
12 |
Tenon couldn’t carry out the test, or couldn’t trust its results |
130 |
Cancelled |
The other codes are Tenon’s own, such as 10
when there’s no license seat.
cd flex/components/Radartenon verify component --flex ../../spectenon verify component --flex ../../spec --dry-runtenon verify component components/Radar --flex ../../spec \ --report reports/verifier/RadarSet up a component test
tenon verify component setup walks you through setting
up a component test in the current folder, one step at a time. It starts
by checking your machine: Docker, Tenon’s image, and licensing. If
there’s no verifier.yaml yet, it then offers to run the
Verifier’s own setup wizard, which asks how your component talks and how
to start it, and writes the file.
With a verifier.yaml in place, setup looks at what it
describes. If a transport needs a broker, such as Kafka, ActiveMQ, NATS
or RabbitMQ, setup offers a test broker in env.toml, and shows the changes
to verifier.yaml that point the Verifier at it, which it
makes only if you agree. It checks that your binary exists, and if the
binary sits in a folder with other files it needs, offers
component_dir so that each run copies the whole folder.
Last, setup offers a pipeline that runs the same test in CI, and asks
whether it’s for GitLab or GitHub. It saves your answers as a
one-component workflow in this folder’s project file, or
inside a larger project, points you at its tenon workflow ci.
Setup never replaces an env.toml or a pipeline file without
asking, and it needs an interactive terminal.
Describing a workflow offers the same setup for each component it tests, so you only need this command for a component on its own, or to redo one.
Command:
tenon verify component setup
cd flex/components/Radartenon verify component setupRead test logs
tenon verify component logs opens the Verifier’s own
logs from a past component test, so that
you can see why a run behaved as it did. The verdict always comes from
the run itself; the logs are the Verifier’s diagnostics. Tenon keeps
them for the last 10 runs of each component, in
.tenon/.verifier/ inside the component folder, so add
.tenon/ to your .gitignore.
On a terminal, it opens the Verifier’s log viewer on the newest run,
and --choose lets you pick another. --list
lists the runs it has kept, newest first, with each one’s result. The
filter options print matching log records instead, as text or as JSON,
for a script or a CI log. Reading logs needs no license seat.
Command:
tenon verify component logs [<dir>] [options]
Arguments
<dir>- The component folder whose logs to read. Defaults to the current folder.
Options
--list- List the runs Tenon has kept, instead of opening the viewer.
--tui- Open the Verifier’s log viewer. The default on a terminal.
--choose- Pick which run to open. Opens the viewer.
--level <trace|debug|info|warning|error>- Print only records at this level.
--scope <prefix>-
Print only records whose scope starts with
<prefix>. --iteration <n>- Print only records from this test iteration.
--protocol <name>- Print only records for this protocol.
--attempt <n>-
Print only records from this attempt at a protocol. Needs
--protocol. --json- Print the matching records as JSON.
tenon verify component logs components/Radartenon verify component logs components/Radar --listtenon verify component logs components/Radar \ --level error --jsonPass options to the Verifier
tenon verify component -- <args> runs the
Verifier’s own command line, with everything after --
passed to it unchanged. Use it for the Verifier’s tools that Tenon
doesn’t cover, such as its manual or its results viewer; the Component test reference
describes them. The Verifier runs in Tenon’s image in Docker, with the
current folder as its own, so the paths you give it are relative to
where you are.
Tenon doesn’t check what the Verifier reports this way, and passes
back its exit code as it is. For a verdict you can rely on, run tenon verify component without
--. A run this way still takes a license seat, and the
Verifier’s interactive tools need a terminal.
Command:
tenon verify component [--network <name>] [--signals <volume|dir>] -- <args>...
Arguments
<args>...- The Verifier’s own subcommand and options.
Options
--network <name>- An existing Docker network for the Verifier to join.
--signals <volume|dir>- A Docker volume or folder that the Verifier shares with a component it controls through signal files.
tenon verify component -- --helptenon verify component -- docs open configComponent files
Each component you test has a folder of its own,
flex/components/<Name>/ in a project, with up
to two files in it. verifier.yaml is the Verifier’s
configuration: how your component talks, how to start it, and how to
test it. env.toml is Tenon’s, and you need it only when the
test needs something beyond your binary, such as a message broker.
Relative paths in both are from the component folder.
The Verifier’s setup wizard writes verifier.yaml; the Configuration and Transports pages
describe every key. Tenon fills in the path to your compiled model
itself, and copies the binary and any other file the configuration names
by a local path into each run, so you never write paths inside Tenon’s
image.
A run copies only those files by default. If your binary needs the
folder it lives in, for shared libraries, configuration or data it opens
by a relative path, set component_dir. Each run then copies
the whole folder, starts your command inside it, and puts the folder,
with its lib/ and lib64/, first on
LD_LIBRARY_PATH. The copy is thrown away after the run, so
your folder is never changed.
env.toml has these keys, all optional. Any other key is
an error, so it can’t give a service extra privileges such as host
networking, volumes or devices.
[verify] profile = "<attach|managed>"-
The default for
--profile. [verify] vconfig = "<file>"-
The Verifier’s configuration file, instead of
verifier.yaml. [verify] component_dir = "<folder>"-
The folder your binary runs from, copied into each run. It must be
inside your Git repository, and the binary
verifier.yamlstarts must be in it. [verify.env] network = "<none|create|existing:<name>>"-
The network for a
managedrun: none, a new one for the run, or an existing Docker network. Defaults tocreatewhen services are declared. [[verify.env.service]]-
A service to start for a
managedrun, such as a test broker. Give each one aname, which is also the hostnameverifier.yamluses to reach it, and animage. It can also haveenv, a table of environment variables;command, a list of arguments for the image;ready, either{ tcp = <port> }to wait until that port answers, or{ sleep_ms = <ms> }; andsignals = true, to share the run’s signal folder with it. In CI, the generated pipeline runs each service as a job service instead.
[verify]
component_dir = "../../../build/radar-install"
[[verify.env.service]]
name = "activemq"
image = "apache/activemq-classic:5.18.6"
ready = { tcp = 61616 }