Skip to content

Bind a virtual service to a test

Use a virtual service dependency when the test calls an API that is slow, costly, rate limited or not built yet. The run calls a virtual service that answers the way you defined it. Leave it out when the real service is cheap and safe to hit under load.

  1. Open the test, go to Dependencies and click Add dependency.
  2. Select the Virtual service kind and pick the service under Choose a virtual service. If it does not exist yet, click Create a virtual service at the foot of the picker. The editor opens in a new tab, so you keep your place.
  3. Type an Env var name, for example PAYMENTS. The hint shows MAXOPERF_VS_PAYMENTS_URL.
  4. Leave Auto-start with the run on, or turn it off.
  5. Click Add.

The injected value is the service’s public address, such as https://payments-a1b2c3.vs.maxoperf.com, without a trailing slash. If the service has a custom domain, that domain is injected instead. Append the path in the script:

const charge = await fetch(`${process.env.MAXOPERF_VS_PAYMENTS_URL}/charges`, { method: 'POST' });

In an HTTP request builder, click Use dependency next to the URL field and pick the service. The field then holds a chip instead of a typed address. See Automate.

Service state when the run startsAuto-start onAuto-start off
RunningThe lease is ready at once.The lease is ready at once.
Deploying or stoppingThe run waits.The run waits.
Stopped, draft or errorThe run deploys it and waits for it to run.The run fails with “is not running and auto-start is disabled”.

A deploy adds its own time before the runners start. The wait is capped by the dependency timeout, 600 seconds by default. If a service you just started enters an error state, the run fails instead of trying again.

When the run ends, MaxoPerf stops the service only if this run started it. A service that was already running stays running. If two runs share a service, the one that started it hands that duty to the other, and the last run to release it stops it.

The Used by list on a virtual service names each test that binds it and how.

The run’s Dependencies tab links each virtual service row to Open analytics. The link opens the service’s Analytics tab limited to the run’s time window. The row carries the note All traffic during this run: the analytics count every request the service received in that window, from any caller. While the run is live, the window has no end yet.