QueryBasicTest. Wait for cluster safe state before running query (backport)

closes #4200