import logging
import time


def update_round_set_and_sleep_if_round_completed(executed_in_current_round: set,
                                                  t: dict) -> set:
    """
    Checks if the string representation of the current test configuration is already in
    the executed_in_current_round set.
    If it is- it means we have already executed this test and the we have reached a round and
    there are tests that
    were not able to be locked by this execution..
    In that case we want to start a new round monitoring by emptying the
    'executed_in_current_round' set and sleep
    in order to let the tests be unlocked
    Args:
        executed_in_current_round: A set containing the string representation of all tests
        configuration as they appear
        in conf.json file that were already executed in the current round
        t: test configuration as it appears in conf.json file

    Returns:
        A new executed_in_current_round set which contains only the current tests configuration if a
        round was completed else it just adds the new test to the set.
    """
    if str(t) in executed_in_current_round:
        logging.info(
            'all tests in the queue were executed, sleeping for 30 seconds to let locked tests get unlocked.')
        executed_in_current_round = set()
        time.sleep(30)
    executed_in_current_round.add(str(t))
    return executed_in_current_round