class_docstr: Test creation of experiment with `client.create_experiment()`
class_docstr_tok: ["Test","creation","of","experiment","with","`","client.create_experiment","(",")","`"]
docstr: Test that a single race condition is handled seamlessly
  
  RaceCondition during registration is already handled by `build()`, therefore we will only
  test for race conditions during version update.
docstr_tok: ["Test","that","a","single","race","condition","is","handled","seamlessly","RaceCondition","during","registration","is","already","handled","by","`","build","(",")","`",",","therefore","we","will","only","test","for","race","conditions","during","version","update","."]
code: def test_create_experiment_race_condition(self, monkeypatch):
      """Test that a single race condition is handled seamlessly
  
      RaceCondition during registration is already handled by `build()`, therefore we will only
      test for race conditions during version update.
      """
      with OrionState(experiments=[config]) as cfg:
          parent = create_experiment(config["name"])
          child = create_experiment(
              config["name"],
              space={"y": "uniform(0, 10)"},
              branching={"enable": True},
              storage=cfg.storage_config,
          )
  
          def insert_race_condition(self, query):
              is_auto_version_query = query == {
                  "name": config["name"],
                  "refers.parent_id": parent.id,
              }
              if is_auto_version_query:
                  data = [child.configuration]
              # First time the query returns no other child
              elif insert_race_condition.count < 1:
                  data = [parent.configuration]
              else:
                  data = [parent.configuration, child.configuration]
  
              insert_race_condition.count += int(is_auto_version_query)
  
              return data
  
          insert_race_condition.count = 0
  
          monkeypatch.setattr(
              setup_storage().__class__,
              "fetch_experiments",
              insert_race_condition,
          )
  
          experiment = create_experiment(
              config["name"],
              space={"y": "uniform(0, 10)"},
              branching={"enable": True},
          )
  
          assert insert_race_condition.count == 1
          assert experiment.version == 2
          assert experiment.configuration == child.configuration
  
imports: import copy
  import json
  from importlib import reload
  import pytest
  import orion.client
  import orion.client.cli
  import orion.core
  from orion.algo.random import Random
  from orion.client import get_experiment
  from orion.client.experiment import ExperimentClient
  from orion.core.io.database.ephemeraldb import EphemeralDB
  from orion.core.io.database.pickleddb import PickledDB
  from orion.core.utils.exceptions import BranchingEvent, NoConfigurationError, RaceCondition, UnsupportedOperation
  from orion.storage.base import setup_storage
  from orion.storage.legacy import Legacy
  from orion.testing import OrionState
label_desc: Use image node_id 9 for calling the TestCreateExperiment obj's underlying member method code with example usage: obj.test_create_experiment_race_condition(monkeypatch) and returns: data