def METHOD_NAME(clean_environment, delete_group):
    """Check agent agent-groups synchronization works as expected.
    This test will wait for the expected agent-groups messages declared in data/synchronization_messages.yml and
    data/delete_messages.yml. Additionally, it will ensure agent-group synchronization is working by adding a group to
    an agent and removing it afterwards."""
    # Get the token
    master_token = host_manager.get_api_token(master_host)
    # Register agent
    agent_ip, agent_id, agent_name, manager_ip = register_agent(test_infra_agents[0], worker_host, host_manager)
    restart_cluster(test_infra_agents, host_manager)
    # Check that the agent is active
    sleep(time_to_sync)
    check_agent_status(agent_id, agent_name, agent_ip, AGENT_STATUS_ACTIVE, host_manager, test_infra_managers)
    HostMonitor(inventory_path=inventory_path, messages_path=sync_messages_path, tmp_path=tmp_path).run()
    # Create group from master
    response = host_manager.make_api_call(host=master_host, method='POST', token=master_token, endpoint='/groups',
                                          request_body={'group_id': test_group})
    assert response['status'] == 200, f"API failure: {response}"
    assert response['json']['message'] == f"Group '{test_group}' created."
    # Check if the new information is present in the master and workers dbs
    sleep(time_to_sync)
    for host in test_infra_managers:
        created_group = execute_wdb_query(f"global '{queries[0]}'", host, host_manager)
        assert f'"name": "{test_group}"' in created_group
    # Add group to agent
    response = host_manager.make_api_call(host=master_host, method='PUT', token=master_token,
                                          endpoint=f"/agents/{agent_id}/group/{test_group}")
    assert response['status'] == 200, f"API failure: {response}"
    assert response['json']['message'] == f"All selected agents were assigned to {test_group}"
    # Check if the new information is present in the master and workers dbs
    sleep(time_to_sync)
    queries.append(f'sync-agent-groups-get {"{"}"condition":"all", "id":{agent_id}{"}"}')
    for host in test_infra_managers:
        assigned_groups = execute_wdb_query(f"global '{queries[1]}'", host, host_manager)
        assert test_group in assigned_groups
    # Check whether the addition messages are present.
    HostMonitor(inventory_path=inventory_path, messages_path=add_messages_path, tmp_path=tmp_path).run()
    # Remove group from agent
    response = host_manager.make_api_call(host=master_host, method='DELETE', token=master_token,
                                          endpoint=f"/agents/{agent_id}/group/{test_group}")
    assert response['status'] == 200, f"API failure: {response}"
    assert response['json']['message'] == f"Agent '{agent_id}' removed from '{test_group}'."
    # Check if the new information is present in the master and workers dbs
    sleep(time_to_sync)
    for host in test_infra_managers:
        assigned_groups = execute_wdb_query(f"global '{queries[1]}'", host, host_manager)
        assert test_group not in assigned_groups
    # Remove group
    response = host_manager.make_api_call(host=master_host, method='DELETE', token=master_token,
                                          endpoint=f"/groups?groups_list={test_group}")
    assert response['status'] == 200, f"API failure: {response}"
    assert response['json']['message'] == 'All selected groups were deleted'
    # Check if the new information is present in the master and workers dbs
    sleep(time_to_sync)
    for host in test_infra_managers:
        created_group = execute_wdb_query(f"global '{queries[0]}'", host, host_manager)
        assert created_group == '[]'
    # Check whether the deletion messages are present.
    HostMonitor(inventory_path=inventory_path, messages_path=delete_messages_path, tmp_path=tmp_path).run()