kapacitor-unit icon indicating copy to clipboard operation
kapacitor-unit copied to clipboard

tests need to delete topic between runs

Open DreadPirateShawn opened this issue 4 years ago • 1 comments

The following tick + test will work fine:

var weather = batch
	| query('''
		SELECT mean(temperature)
		FROM "weather"."default"."temperature"
		''')
			.period(5m)
			.every(10m)

	weather
	| alert().id('Temperature')
		.topic('weather')
		.message('Temperature alert - batch')
		.warn(lambda: "mean" > 80)
		.crit(lambda: "mean" > 100)
		.stateChangesOnly()
    .log('/tmp/temperature_batch.tick.log')
tests:

  - name: "Alert weather:: batch"
    task_name: alert_weather_batch.tick
    db: weather
    rp: default
    type: batch
    data:
      - temperature,location=us-midwest temperature=110
      - temperature,location=us-midwest temperature=91
    expects:
      ok: 0
      warn: 0
      crit: 1

However, if a topic is added to the tick:

	| alert().id('Temperature')
		.topic('weather')

...then the test will only work once, and will fail on subsequent runs.

This is due to .stateChangesOnly() combined with the lack of topic state deletion between test runs.

That is to say -- in kapacitor, the "weather" topic tracks the critical state of the task, so even deleting and recreating the task between tests in not sufficient to reset the state.

The problem is confirmed for batch, unconfirmed for stream.

DreadPirateShawn avatar Mar 24 '20 21:03 DreadPirateShawn

Topic cleanup added in https://github.com/DreadPirateShawn/kapacitor-unit

(With apologies, I've fully forked rather than pushing upstream PRs, since the upstream doesn't really have an active maintainer.)

DreadPirateShawn avatar Mar 24 '20 23:03 DreadPirateShawn