def METHOD_NAME(context, name1, name2, role, group, time_limit):
    time_limit *= context.timeout_multiplier
    max_time = time.time() + int(time_limit)
    worker_port = int(context.pctl.query(name1, "SHOW port").fetchone()[0])
    while time.time() < max_time:
        try:
            cur = context.pctl.query(name2, "SELECT nodeport, noderole"
                                            " FROM pg_catalog.pg_dist_node WHERE groupid = {0}".format(group))
            mapping = {r[0]: r[1] for r in cur}
            if mapping.get(worker_port) == role:
                return
        except Exception:
            pass
        time.sleep(1)
    assert False, "Node {0} is not registered in pg_dist_node on the node {1}".format(name1, name2)