code: def test_sql_tracker_store_with_login_db_race_condition(
      postgres_login_db_connection: sa.engine.Connection,
      caplog: LogCaptureFixture,
      monkeypatch: MonkeyPatch,
  ):
      original_execute = sa.engine.Connection.execute
  
      def mock_execute(self, *args, **kwargs):
          # this simulates a race condition
          if kwargs == {"database_name": POSTGRES_TRACKER_STORE_DB}:
              original_execute(
                  self.execution_options(isolation_level="AUTOCOMMIT"),
                  f"CREATE DATABASE {POSTGRES_TRACKER_STORE_DB}",
              )
              return Mock(rowcount=0)
          else:
              return original_execute(self, *args, **kwargs)
  
      with monkeypatch.context() as mp:
          mp.setattr(sa.engine.Connection, "execute", mock_execute)
          with caplog.at_level(logging.ERROR):
              tracker_store = SQLTrackerStore(
                  dialect="postgresql",
                  host=POSTGRES_HOST,
                  port=POSTGRES_PORT,
                  username=POSTGRES_USER,
                  password=POSTGRES_PASSWORD,
                  db=POSTGRES_TRACKER_STORE_DB,
                  login_db=POSTGRES_LOGIN_DB,
              )
  
      # IntegrityError has been caught and we log the error
      assert any(
          [
              f"Could not create database '{POSTGRES_TRACKER_STORE_DB}'"
              in record.message
              for record in caplog.records
          ]
      )
      matching_rows = (
          postgres_login_db_connection.execution_options(
              isolation_level="AUTOCOMMIT"
          )
          .execute(
              sa.text(
                  "SELECT 1 FROM pg_catalog.pg_database WHERE datname = :database_name"
              ),
              database_name=POSTGRES_TRACKER_STORE_DB,
          )
          .rowcount
      )
      assert matching_rows == 1
      tracker_store.engine.dispose()
  
file_path: rasa/tests/integration_tests/core/test_tracker_store.py
imports: import logging
  from typing import List
  from unittest.mock import Mock
  import pytest
  from _pytest.logging import LogCaptureFixture
  from _pytest.monkeypatch import MonkeyPatch
  import sqlalchemy
  from rasa.core.tracker_store import MongoTrackerStore, RedisTrackerStore, SQLTrackerStore
  from rasa.shared.core.domain import Domain
  from rasa.shared.core.events import Event
  from rasa.shared.core.trackers import DialogueStateTracker
  from .conftest import POSTGRES_HOST, POSTGRES_PORT, POSTGRES_LOGIN_DB, POSTGRES_TRACKER_STORE_DB, POSTGRES_USER, POSTGRES_PASSWORD
label_desc: Use image node_id 3 for calling a global function with example usage: test_sql_tracker_store_with_login_db_race_condition(postgres_login_db_connection, caplog, monkeypatch) and returns: Mock, original_execute