-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.diff
More file actions
48 lines (44 loc) · 1.75 KB
/
Copy pathpatch.diff
File metadata and controls
48 lines (44 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--- tests/test_config.py
+++ tests/test_config.py
@@ -53,34 +53,24 @@
"""Test concurrent access to the get method."""
config = ConfigManager()
# Initialize with some data
- for i in range(100):
+ for i in range(50):
config.set(f"key_{i}", i)
- errors = []
-
def reader_task():
- try:
- for _ in range(1000):
- # Randomly read keys, some exist, some don't
- config.get("key_50", default="fallback")
- config.get("missing_key", default="fallback")
- except Exception as e:
- errors.append(e)
+ for _ in range(100):
+ # Randomly read keys, some exist, some don't
+ config.get("key_25", default="fallback")
+ config.get("missing_key", default="fallback")
def writer_task():
- try:
- for i in range(100, 200):
- config.set(f"key_{i}", i)
- except Exception as e:
- errors.append(e)
+ for i in range(50, 70):
+ config.set(f"key_{i}", i)
# Run multiple readers and writers concurrently
with ThreadPoolExecutor(max_workers=10) as executor:
# 8 readers, 2 writers
futures = []
for _ in range(8):
futures.append(executor.submit(reader_task))
for _ in range(2):
futures.append(executor.submit(writer_task))
+ # Calling future.result() will propagate any exceptions with their full traceback
for future in futures:
future.result()
-
- self.assertEqual(len(errors), 0, f"Thread safety errors occurred: {errors}")