How to know when k6 is done reporting metrics

I’m noticing that teardown() is being called after k6 is finished running tests, but not necessarily after k6 has finished reporting metrics to its output, such as a kafka or influxdb server. How can I tell when k6 is done reporting these metrics to the external server?

Sorry for the delayed response! Unfortunately, there’s no way to synchronize the reporting of metrics and the call of teardown(), simply because requests in teardown() can still generate metrics that would need to be reported to the external output.

If you want to somewhat ensure that the rest of the metrics have been reported to InfluxDB, the only workaround I can think of is to add some sleep() in the beginning of the teardown() call (and increase the teardownTimeout option to something greater than the default 10s), so it waits for a few seconds (the InfluxDB metrics push interval is 1 second)

1 Like