code: def test_duplicate_race_conditions(storage, monkeypatch, caplog):
      """Test that duplication does not raise an error during race conditions."""
      with disable_duplication(monkeypatch):
          build_evc_tree(list(range(2)))
  
      experiment = build_experiment(name="parent")
  
      def register_race_condition(trial):
          raise DuplicateKeyError("Race condition!")
  
      monkeypatch.setattr(
          experiment._experiment._storage,
          "register_trial",
          register_race_condition,
      )
  
      assert len(experiment.fetch_trials(with_evc_tree=False)) == len(
          Trial.allowed_stati
      )
  
      with caplog.at_level(logging.DEBUG):
          experiment._experiment.duplicate_pending_trials()
  
          assert (
              "Race condition while trying to duplicate trial"
              in caplog.text
          )
  
file_path: orion/tests/functional/core/worker/test_experiment_functional.py
imports: import logging
  from orion.client import build_experiment, get_experiment
  from orion.core.io.database import DuplicateKeyError
  from orion.core.worker.trial import Trial
  from orion.testing import mocked_datetime
  from orion.testing.evc import build_child_experiment, build_root_experiment, disable_duplication
label_desc: Use image node_id 6 for calling a global function with example usage: test_duplicate_race_conditions(storage, monkeypatch, caplog) without return types