Make waiting for API events in tests more convenient#541
Closed
Make waiting for API events in tests more convenient#541
Conversation
a9d745a to
9aa8c7a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The purpose of this PR is to facilitate writing test scenarios with steps that wait for particular API events in addition to (or instead of) waiting for particular log entries.
Main changes:
The method
Runner.wait_for_api_event(predicate, ...)is added. It can be used to wait until an API event satisfying given predicate is registered by MITM proxy, much like the existing methodProbe.wait_for_log(predicate, ...)is used to wait until a log entry satisfying given predicate occurs in the agent log stream for a particular probe. Unlike in case of log monitors examined byProbe.wait_for_log(), the methodRunner.wait_for_api_event()processes API events from all nodes, treated as a single stream of events.The method
EventMonitor.wait_for_event(), used internally by bothRunner.wait_for_api_event()andProbe.wait_for_log(), is modified to accept a more general predicate that can accept arbitrary positional and keyword arguments, along with the event. The predicate can also return an arbitrary type: conversion toboolis used to determine if the predicate accepts given event. Value returned by the predicate for the accepted event is returned along with the event fromEventMonitor.wait_for_event().Some predicates for API events are added to
goth.api_monitor.api_eventmodule.