| 1 |
import time |
| 2 |
from concurrent.futures import ThreadPoolExecutor |
| 3 |
|
| 4 |
import pytest |
| 5 |
|
| 6 |
from django_pgschemas import Schema, get_current_schema |
| 7 |
|
| 8 |
FIRST_SCHEMA = "first_schema" |
| 9 |
SECOND_SCHEMA = "second_schema" |
| 10 |
|
| 11 |
|
| 12 |
@pytest.mark.bug |
| 13 |
def test_multithread_with_schema(): |
| 14 |
def handle_schema(): |
| 15 |
with Schema.create(schema_name=FIRST_SCHEMA): |
| 16 |
assert get_current_schema().schema_name == FIRST_SCHEMA |
| 17 |
|
| 18 |
with Schema.create(schema_name=SECOND_SCHEMA): |
| 19 |
assert get_current_schema().schema_name == SECOND_SCHEMA |
| 20 |
time.sleep(0.001) |
| 21 |
|
| 22 |
assert get_current_schema().schema_name == FIRST_SCHEMA |
| 23 |
|
| 24 |
return get_current_schema().schema_name |
| 25 |
|
| 26 |
with ThreadPoolExecutor(max_workers=15) as executor: |
| 27 |
futures = [executor.submit(handle_schema) for _ in range(15)] |
| 28 |
results = [future.result() for future in futures] |
| 29 |
assert all(value == FIRST_SCHEMA for value in results) |