def METHOD_NAME(integration_check, pg_instance):
    """
    Test cache refresh by adding a database in the middle of a check.
    """
    database_to_find = "cats"
    @contextmanager
    def get_postgres_connection():
        conn_args = {'host': HOST, 'dbname': "postgres", 'user': USER_ADMIN, 'password': PASSWORD_ADMIN}
        conn = psycopg.connect(**conn_args)
        conn.autocommit = True
        yield conn
    pg_instance["database_autodiscovery"] = copy.deepcopy(DISCOVERY_CONFIG)
    pg_instance['database_autodiscovery']['include'].append(database_to_find)
    pg_instance['relations'] = ['pg_index']
    del pg_instance['dbname']
    pg_instance["database_autodiscovery"]['refresh'] = 1
    check = integration_check(pg_instance)
    run_one_check(check, pg_instance)
    assert check.autodiscovery is not None
    databases = check.autodiscovery.get_items()
    expected_len = NUM_DOGS_DATABASES - len(DISCOVERY_CONFIG["exclude"])
    assert len(databases) == expected_len
    with get_postgres_connection() as conn:
        cursor = conn.cursor()
        try:
            cursor.execute(sql.SQL("CREATE DATABASE {}").format(sql.Identifier(database_to_find)))
            time.sleep(pg_instance["database_autodiscovery"]['refresh'])
            databases = check.autodiscovery.get_items()
            assert len(databases) == expected_len + 1
        finally:
            # Need to drop the new database to clean up the environment for next tests.
            cursor.execute(sql.SQL("DROP DATABASE {} WITH (FORCE);").format(sql.Identifier(database_to_find)))