-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
consider adding facilities to inspect all statuses added to the collect status event. #79
Comments
I think we should only verify the resulting status, otherwise it seems like we're testing implementation details. It's not a log where you may want to verify logs A, B, and C were sent out. A charm could call |
Countering the above, we've had a discussion where a following hypothetical was presented:
Here's an example off the top of my head: # Common setup
kafka_broker = MockKafkaBroker.return_value
zookeeper_client = MockZookeeperClient.return_value
zookeeper_client.is_connected.return_value = True
kafka_broker.is_healthy.return_value = True
kafka_broker.get_replication_status.return_value = 'healthy'
# Test 1
kafka_broker.is_healthy.return_value = False
kafka_broker.health_check.side_effect = TimeoutError("Broker health check timed out")
assert XXX
# Test 2
kafka_broker.get_disk_usage.return_value = 95 # Percentage used
assert YYY
# Test 3
kafka_broker.get_replication_status.return_value = 'stuck'
kafka_broker.get_replication_error.return_value = "Replication slot is stuck"
assert ZZZ A multi-error API would allow tests like: # Test 1
assert "kafka is not healthy" in foo.status_elements
assert "timed out" in foo.status_elements While a single-error API requires very specific test setup, e.g. # Test 1
# Lie about healthy status to have the timeout bubble up
kafka_broker.is_healthy.return_value = True
kafka_broker.health_check.side_effect = TimeoutError("Broker health check timed out")
assert "timed out" in foo.combined_status and separately # Test 1
kafka_broker.is_healthy.return_value = False
kafka_broker.health_check.return_value = True
assert "not healthy" in foo.combined_status I could be a small issue or a bigger one, depending on the tooling to mock out specific workload client API. Hand-written mocks probably don't care as much. On the other hand, if charmer used some off-the-shelf mocks, like the WDYT? |
Yeah, I can see what you're saying -- with only a single status, the person writing tests might have to know more about the implementation details to write the test than with a list of statuses. Would be interested to hear what @tonyandrewmeyer has to say, and @PietroPasotti -- in practice, which approach do you think would require you to have to know more implementation details about the charm (and therefore be a brittler test)? |
I think a feature of this kind would allow you to write simpler tests.
then we wouldn't have to also mock relation and container when we're testing the status that depends on the API. Alternatively we could recommend folks to redesign their code and have the charm define separate |
Thanks. I'm convinced by Dima and Pietro's arguments here -- this would make testing that kind of thing less fragile. |
For what it's worth, I think this could be a set (all the examples above are |
Ah yes, very much agreed on set (unordered) vs list (ordered). |
Moved to canonical/operator#1426 |
should we add something to facilitate verifying all of the individual statuses that went into the collect-status event, or are we happy with verifying that the highest priority one is what we think it is?
Food for thought.
Originally posted by @PietroPasotti in #78 (comment)
The text was updated successfully, but these errors were encountered: