tests/migration-tests: migration_event_wait()
Introduce a small helper to wait for a migration event, generalized from the incoming migration path. Make the helper easier to use by allowing it to keep waiting until the expected event is received. Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Fabiano Rosas <farosas@suse.de> Signed-off-by: Fabiano Rosas <farosas@suse.de>
This commit is contained in:
parent
cd313b66f2
commit
d444e5673c
@ -249,7 +249,7 @@ void migrate_set_capability(QTestState *who, const char *capability,
|
||||
void migrate_incoming_qmp(QTestState *to, const char *uri, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
QDict *args, *rsp, *data;
|
||||
QDict *args, *rsp;
|
||||
|
||||
va_start(ap, fmt);
|
||||
args = qdict_from_vjsonf_nofail(fmt, ap);
|
||||
@ -272,14 +272,7 @@ void migrate_incoming_qmp(QTestState *to, const char *uri, const char *fmt, ...)
|
||||
g_assert(qdict_haskey(rsp, "return"));
|
||||
qobject_unref(rsp);
|
||||
|
||||
rsp = qtest_qmp_eventwait_ref(to, "MIGRATION");
|
||||
g_assert(qdict_haskey(rsp, "data"));
|
||||
|
||||
data = qdict_get_qdict(rsp, "data");
|
||||
g_assert(qdict_haskey(data, "status"));
|
||||
g_assert_cmpstr(qdict_get_str(data, "status"), ==, "setup");
|
||||
|
||||
qobject_unref(rsp);
|
||||
migration_event_wait(to, "setup");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -518,3 +511,23 @@ bool probe_o_direct_support(const char *tmpfs)
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Wait for a "MIGRATION" event. This is what Libvirt uses to track
|
||||
* migration status changes.
|
||||
*/
|
||||
void migration_event_wait(QTestState *s, const char *target)
|
||||
{
|
||||
QDict *response, *data;
|
||||
const char *status;
|
||||
bool found;
|
||||
|
||||
do {
|
||||
response = qtest_qmp_eventwait_ref(s, "MIGRATION");
|
||||
data = qdict_get_qdict(response, "data");
|
||||
g_assert(data);
|
||||
status = qdict_get_str(data, "status");
|
||||
found = (strcmp(status, target) == 0);
|
||||
qobject_unref(response);
|
||||
} while (!found);
|
||||
}
|
||||
|
@ -63,4 +63,6 @@ static inline bool probe_o_direct_support(const char *tmpfs)
|
||||
}
|
||||
#endif
|
||||
void migration_test_add(const char *path, void (*fn)(void));
|
||||
void migration_event_wait(QTestState *s, const char *target);
|
||||
|
||||
#endif /* MIGRATION_HELPERS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user