frontrun 0.2.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. {frontrun-0.2.0 → frontrun-0.4.0}/Cargo.lock +2 -2
  2. {frontrun-0.2.0 → frontrun-0.4.0}/Cargo.toml +1 -1
  3. {frontrun-0.2.0 → frontrun-0.4.0}/PKG-INFO +20 -6
  4. {frontrun-0.2.0 → frontrun-0.4.0}/README.md +17 -5
  5. frontrun-0.4.0/crates/dpor/src/access.rs +163 -0
  6. {frontrun-0.2.0 → frontrun-0.4.0}/crates/dpor/src/engine.rs +274 -86
  7. {frontrun-0.2.0 → frontrun-0.4.0}/crates/dpor/src/lib.rs +104 -7
  8. {frontrun-0.2.0 → frontrun-0.4.0}/crates/dpor/src/object.rs +7 -6
  9. frontrun-0.4.0/crates/dpor/src/path.rs +2092 -0
  10. {frontrun-0.2.0 → frontrun-0.4.0}/crates/dpor/src/wakeup_tree.rs +1 -1
  11. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_cooperative.py +204 -85
  12. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_deadlock.py +49 -2
  13. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_io_detection.py +0 -1
  14. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_redis_client.py +44 -12
  15. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_redis_parsing.py +5 -3
  16. frontrun-0.4.0/frontrun/_report.py +183 -0
  17. frontrun-0.4.0/frontrun/_report_template.html +1428 -0
  18. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_sql_cursor.py +159 -8
  19. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_sql_parsing.py +30 -6
  20. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_trace_format.py +9 -5
  21. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_tracing.py +29 -0
  22. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/async_dpor.py +34 -15
  23. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/async_scheduler.py +30 -17
  24. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/async_trace_markers.py +2 -5
  25. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/bytecode.py +11 -5
  26. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/contrib/sqlalchemy/_sync.py +48 -6
  27. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/dpor.py +1187 -88
  28. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/pytest_plugin.py +26 -0
  29. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/trace_markers.py +197 -1
  30. {frontrun-0.2.0 → frontrun-0.4.0}/pyproject.toml +2 -0
  31. frontrun-0.2.0/crates/dpor/src/access.rs +0 -55
  32. frontrun-0.2.0/crates/dpor/src/path.rs +0 -1223
  33. {frontrun-0.2.0 → frontrun-0.4.0}/LICENSE +0 -0
  34. {frontrun-0.2.0 → frontrun-0.4.0}/crates/dpor/Cargo.toml +0 -0
  35. {frontrun-0.2.0 → frontrun-0.4.0}/crates/dpor/src/thread.rs +0 -0
  36. {frontrun-0.2.0 → frontrun-0.4.0}/crates/dpor/src/vv.rs +0 -0
  37. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/Makefile +0 -0
  38. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/__init__.py +0 -0
  39. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_preload_io.py +0 -0
  40. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_real_threading.py +0 -0
  41. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_redis_client_async.py +0 -0
  42. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_schema.py +0 -0
  43. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_sql_anomaly.py +0 -0
  44. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_sql_cursor_async.py +0 -0
  45. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_sql_insert_tracker.py +0 -0
  46. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_sql_params.py +0 -0
  47. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/_sql_predicates.py +0 -0
  48. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/async_shuffler.py +0 -0
  49. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/cli.py +0 -0
  50. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/common.py +0 -0
  51. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/contrib/__init__.py +0 -0
  52. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/contrib/django/__init__.py +0 -0
  53. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/contrib/django/_async.py +0 -0
  54. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/contrib/django/_sync.py +0 -0
  55. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/contrib/sqlalchemy/__init__.py +0 -0
  56. {frontrun-0.2.0 → frontrun-0.4.0}/frontrun/contrib/sqlalchemy/_async.py +0 -0
@@ -10,14 +10,14 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
10
10
 
11
11
  [[package]]
12
12
  name = "frontrun-dpor"
13
- version = "0.2.0"
13
+ version = "0.4.0"
14
14
  dependencies = [
15
15
  "pyo3",
16
16
  ]
17
17
 
18
18
  [[package]]
19
19
  name = "frontrun-io"
20
- version = "0.2.0"
20
+ version = "0.4.0"
21
21
  dependencies = [
22
22
  "libc",
23
23
  "once_cell",
@@ -3,4 +3,4 @@ members = ["crates/dpor"]
3
3
  resolver = "2"
4
4
 
5
5
  [workspace.package]
6
- version = "0.2.0"
6
+ version = "0.4.0"
@@ -1,12 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: frontrun
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: Programming Language :: Python :: 3
7
7
  Classifier: Programming Language :: Python :: 3.10
8
8
  Classifier: Programming Language :: Python :: 3.11
9
9
  Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
11
+ Classifier: Programming Language :: Python :: 3.14
10
12
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
11
13
  Classifier: Topic :: Software Development :: Testing
12
14
  Requires-Dist: pytest>=7.0 ; extra == 'dev'
@@ -52,15 +54,25 @@ Frontrun is named after the insider trading crime where someone uses insider inf
52
54
 
53
55
  The core problem: race conditions are hard to test because they depend on timing. A test that passes 95% of the time is worse than a test that always fails, because it breeds false confidence. Frontrun replaces timing-dependent thread interleaving with deterministic scheduling, so race conditions either always happen or never happen.
54
56
 
55
- Three approaches, in order of decreasing interpretability:
57
+ Four approaches, in order of decreasing interpretability:
56
58
 
57
- 1. **Trace markers** — Comment-based synchronization points (`# frontrun: marker_name`) that let you force a specific execution order. Useful when you already know the race window and want to reproduce it deterministically in a test.
59
+ 1. **DPOR** — Systematically explores every meaningfully different interleaving. When it finds a race, it tells you exactly which shared-memory accesses conflicted and in what order. Powered by a Rust engine using vector clocks to prune redundant orderings.
58
60
 
59
- 2. **DPOR** — Systematically explores every meaningfully different interleaving. When it finds a race, it tells you exactly which shared-memory accesses conflicted and in what order. Powered by a Rust engine using vector clocks to prune redundant orderings.
61
+ 2. **Bytecode exploration** — Generates random opcode-level schedules and checks an invariant under each one. Often finds races very efficiently (sometimes on the first attempt), and can catch races that are invisible to DPOR (e.g. shared state inside C extensions). The trade-off: error traces show *what happened* but not *why* — you get the interleaving that broke the invariant, not a causal explanation.
60
62
 
61
- 3. **Bytecode exploration** — Generates random opcode-level schedules and checks an invariant under each one. Often finds races very efficiently (sometimes on the first attempt), and can catch races that are invisible to DPOR (e.g. shared state inside C extensions). The trade-off: error traces show *what happened* but not *why* — you get the interleaving that broke the invariant, not a causal explanation.
63
+ 3. **Marker schedule exploration** — Exhaustive exploration of all interleavings at the `# frontrun:` marker level. Much smaller search space than bytecode exploration, with completeness guarantees.
62
64
 
63
- All three have async variants. A C-level `LD_PRELOAD` library intercepts libc I/O for database drivers and other opaque extensions.
65
+ 4. **Trace markers** — Comment-based synchronization points (`# frontrun: marker_name`) that let you force a specific execution order. Useful when you already know the race window and want to reproduce it deterministically in a test.
66
+
67
+ All four have async variants. A C-level `LD_PRELOAD` library intercepts libc I/O for database drivers and other opaque extensions.
68
+
69
+ ### DPOR deadlock detection (dining philosophers)
70
+
71
+ DPOR explores thread interleavings and detects deadlocks via wait-for-graph cycle analysis. Here it finds the circular wait in the classic 3-philosopher dining problem:
72
+
73
+ ![Deadlock diagram showing DPOR exploration of the dining philosophers problem. Three threads each acquire one fork (lock) then block waiting for the next, forming a cycle.](docs/_static/deadlock-diagram.png)
74
+
75
+ The timeline shows each thread's lock acquisitions (green), context switches (pink arrows), and the point where the deadlock is detected. Run `make screenshot` to regenerate this image from `examples/dpor_dining_philosophers.py`.
64
76
 
65
77
  ## Quick Start: Bank Account Race Condition
66
78
 
@@ -190,6 +202,8 @@ Race condition found after 2 interleavings.
190
202
 
191
203
  DPOR explored exactly 2 interleavings out of the 6 possible (the other 4 are equivalent to one of the first two). For a detailed walkthrough of how this works, see the [DPOR algorithm documentation](docs/dpor.rst).
192
204
 
205
+ **Search strategies:** The default DFS strategy is optimal for **exhaustive exploration** (`stop_on_first=False`) — it produces the minimum number of executions. When the trace space is very large and you have a limited execution budget (`stop_on_first=True` or a low `max_executions`), use a non-DFS strategy like `search="bit-reversal"` to spread exploration across diverse conflict points early, finding bugs faster on average. See [search strategy documentation](docs/search.rst) for details.
206
+
193
207
  **Scope and limitations:** DPOR tracks Python bytecode-level conflicts (attribute and subscript reads/writes, lock operations) plus I/O. Redis key-level conflicts are detected by intercepting redis-py's `execute_command()` (sync; active with `detect_io=True`) or via `detect_redis=True` (async). SQL conflicts are detected by intercepting DBAPI `cursor.execute()`. These key/table-level detectors are important: raw socket detection uses `host:port` as the resource ID, so every send and recv to the same server appears to conflict — without key-level or SQL-level refinement this causes a combinatorial explosion of spurious interleavings. C-extension shared state (NumPy arrays, etc.) is not tracked at all. The `frontrun` CLI adds C-level socket interception via `LD_PRELOAD` for opaque drivers, also at the coarse `host:port` level.
194
208
 
195
209
  ### 3. Bytecode Exploration
@@ -12,15 +12,25 @@ Frontrun is named after the insider trading crime where someone uses insider inf
12
12
 
13
13
  The core problem: race conditions are hard to test because they depend on timing. A test that passes 95% of the time is worse than a test that always fails, because it breeds false confidence. Frontrun replaces timing-dependent thread interleaving with deterministic scheduling, so race conditions either always happen or never happen.
14
14
 
15
- Three approaches, in order of decreasing interpretability:
15
+ Four approaches, in order of decreasing interpretability:
16
16
 
17
- 1. **Trace markers** — Comment-based synchronization points (`# frontrun: marker_name`) that let you force a specific execution order. Useful when you already know the race window and want to reproduce it deterministically in a test.
17
+ 1. **DPOR** — Systematically explores every meaningfully different interleaving. When it finds a race, it tells you exactly which shared-memory accesses conflicted and in what order. Powered by a Rust engine using vector clocks to prune redundant orderings.
18
18
 
19
- 2. **DPOR** — Systematically explores every meaningfully different interleaving. When it finds a race, it tells you exactly which shared-memory accesses conflicted and in what order. Powered by a Rust engine using vector clocks to prune redundant orderings.
19
+ 2. **Bytecode exploration** — Generates random opcode-level schedules and checks an invariant under each one. Often finds races very efficiently (sometimes on the first attempt), and can catch races that are invisible to DPOR (e.g. shared state inside C extensions). The trade-off: error traces show *what happened* but not *why* — you get the interleaving that broke the invariant, not a causal explanation.
20
20
 
21
- 3. **Bytecode exploration** — Generates random opcode-level schedules and checks an invariant under each one. Often finds races very efficiently (sometimes on the first attempt), and can catch races that are invisible to DPOR (e.g. shared state inside C extensions). The trade-off: error traces show *what happened* but not *why* — you get the interleaving that broke the invariant, not a causal explanation.
21
+ 3. **Marker schedule exploration** — Exhaustive exploration of all interleavings at the `# frontrun:` marker level. Much smaller search space than bytecode exploration, with completeness guarantees.
22
22
 
23
- All three have async variants. A C-level `LD_PRELOAD` library intercepts libc I/O for database drivers and other opaque extensions.
23
+ 4. **Trace markers** — Comment-based synchronization points (`# frontrun: marker_name`) that let you force a specific execution order. Useful when you already know the race window and want to reproduce it deterministically in a test.
24
+
25
+ All four have async variants. A C-level `LD_PRELOAD` library intercepts libc I/O for database drivers and other opaque extensions.
26
+
27
+ ### DPOR deadlock detection (dining philosophers)
28
+
29
+ DPOR explores thread interleavings and detects deadlocks via wait-for-graph cycle analysis. Here it finds the circular wait in the classic 3-philosopher dining problem:
30
+
31
+ ![Deadlock diagram showing DPOR exploration of the dining philosophers problem. Three threads each acquire one fork (lock) then block waiting for the next, forming a cycle.](docs/_static/deadlock-diagram.png)
32
+
33
+ The timeline shows each thread's lock acquisitions (green), context switches (pink arrows), and the point where the deadlock is detected. Run `make screenshot` to regenerate this image from `examples/dpor_dining_philosophers.py`.
24
34
 
25
35
  ## Quick Start: Bank Account Race Condition
26
36
 
@@ -150,6 +160,8 @@ Race condition found after 2 interleavings.
150
160
 
151
161
  DPOR explored exactly 2 interleavings out of the 6 possible (the other 4 are equivalent to one of the first two). For a detailed walkthrough of how this works, see the [DPOR algorithm documentation](docs/dpor.rst).
152
162
 
163
+ **Search strategies:** The default DFS strategy is optimal for **exhaustive exploration** (`stop_on_first=False`) — it produces the minimum number of executions. When the trace space is very large and you have a limited execution budget (`stop_on_first=True` or a low `max_executions`), use a non-DFS strategy like `search="bit-reversal"` to spread exploration across diverse conflict points early, finding bugs faster on average. See [search strategy documentation](docs/search.rst) for details.
164
+
153
165
  **Scope and limitations:** DPOR tracks Python bytecode-level conflicts (attribute and subscript reads/writes, lock operations) plus I/O. Redis key-level conflicts are detected by intercepting redis-py's `execute_command()` (sync; active with `detect_io=True`) or via `detect_redis=True` (async). SQL conflicts are detected by intercepting DBAPI `cursor.execute()`. These key/table-level detectors are important: raw socket detection uses `host:port` as the resource ID, so every send and recv to the same server appears to conflict — without key-level or SQL-level refinement this causes a combinatorial explosion of spurious interleavings. C-extension shared state (NumPy arrays, etc.) is not tracked at all. The `frontrun` CLI adds C-level socket interception via `LD_PRELOAD` for opaque drivers, also at the coarse `host:port` level.
154
166
 
155
167
  ### 3. Bytecode Exploration
@@ -0,0 +1,163 @@
1
+ //! DPOR access tracking.
2
+ //!
3
+ //! Records shared memory accesses for race detection. Two accesses form a
4
+ //! **race** (JACM'17 Def 3.3 p.13-14) when they are from different threads,
5
+ //! at least one is a write, they access the same object, and they are not
6
+ //! ordered by the happens-before relation.
7
+
8
+ use crate::vv::VersionVec;
9
+
10
+ /// Provenance tag indicating how an access was generated.
11
+ ///
12
+ /// Each access is tagged with its origin so that future merge strategies
13
+ /// can apply per-origin policies (e.g., treating I/O accesses differently
14
+ /// from Python memory accesses during sleep-set propagation).
15
+ ///
16
+ /// Ordering by "strength": `IoDirect` > `LockSynthetic` > `PythonMemory`.
17
+ /// When merging two accesses with different origins, the stronger one wins.
18
+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]
19
+ pub enum AccessOrigin {
20
+ /// Access observed via Python shared-memory tracing (sys.settrace).
21
+ PythonMemory,
22
+ /// Synthetic access generated for lock acquire/release conflict tracking.
23
+ LockSynthetic,
24
+ /// Direct I/O access (file, socket, database) intercepted at the C level.
25
+ IoDirect,
26
+ }
27
+
28
+ impl AccessOrigin {
29
+ /// Merge two origins, keeping the "stronger" one.
30
+ /// Strength order: `IoDirect` > `LockSynthetic` > `PythonMemory`.
31
+ pub fn merge(self, other: Self) -> Self {
32
+ match (self, other) {
33
+ _ if self == other => self,
34
+ (AccessOrigin::IoDirect, _) | (_, AccessOrigin::IoDirect) => AccessOrigin::IoDirect,
35
+ (AccessOrigin::LockSynthetic, _) | (_, AccessOrigin::LockSynthetic) => {
36
+ AccessOrigin::LockSynthetic
37
+ }
38
+ _ => AccessOrigin::PythonMemory,
39
+ }
40
+ }
41
+ }
42
+
43
+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]
44
+ pub enum AccessKind {
45
+ Read,
46
+ Write,
47
+ /// Like `Write` but does NOT conflict with other `WeakWrite`s or
48
+ /// `WeakRead`s.
49
+ ///
50
+ /// Used for container-level subscript writes (`STORE_SUBSCR`): these
51
+ /// should conflict with C-method reads (iteration, `len()`) but two
52
+ /// subscript writes on different keys of the same container should
53
+ /// NOT conflict with each other.
54
+ WeakWrite,
55
+ /// Like `Read` but does NOT conflict with `WeakWrite`s or other
56
+ /// `WeakRead`s.
57
+ ///
58
+ /// Used for `LOAD_ATTR` on mutable values: loading a container just
59
+ /// to subscript it shouldn't conflict with subscript writes on
60
+ /// disjoint keys, but should still conflict with C-method writes
61
+ /// (append, clear, etc.).
62
+ WeakRead,
63
+ }
64
+
65
+ impl AccessKind {
66
+ /// Merge two access kinds into a single kind whose conflict set is a
67
+ /// superset of both inputs' conflict sets. Used by trace caching and
68
+ /// per-branch access recording when the same object is accessed with
69
+ /// different kinds.
70
+ ///
71
+ /// The key improvement over the naive "if different, upgrade to Write"
72
+ /// is that `Read` subsumes `WeakRead`: Read conflicts with {Write,
73
+ /// WeakWrite}, WeakRead conflicts with {Write} — so Read already
74
+ /// covers WeakRead's conflicts. Upgrading Read+WeakRead to Write
75
+ /// would make the thread appear to *write* the object, causing
76
+ /// spurious sleep-set wakeups when another thread reads it.
77
+ pub fn merge(self, other: Self) -> Self {
78
+ if self == other {
79
+ return self;
80
+ }
81
+ match (self, other) {
82
+ // Read subsumes WeakRead (Read ⊇ WeakRead in conflict sets)
83
+ (AccessKind::Read, AccessKind::WeakRead)
84
+ | (AccessKind::WeakRead, AccessKind::Read) => AccessKind::Read,
85
+ // WeakWrite subsumes WeakRead: WeakWrite conflicts with {Read, Write},
86
+ // WeakRead conflicts with {Write}. WeakWrite's conflict set is a superset.
87
+ (AccessKind::WeakWrite, AccessKind::WeakRead)
88
+ | (AccessKind::WeakRead, AccessKind::WeakWrite) => AccessKind::WeakWrite,
89
+ // Write subsumes everything
90
+ _ => AccessKind::Write,
91
+ }
92
+ }
93
+ }
94
+
95
+ /// Records an access to a shared object for DPOR dependency detection.
96
+ /// The `path_id` identifies the scheduling point (position in the execution
97
+ /// sequence E), used to determine where to insert into wakeup trees.
98
+ /// The `dpor_vv` captures the happens-before state at the time of access,
99
+ /// used to check for races: e ⋖_E e' when ¬(e →_E e') (JACM'17 p.13-14).
100
+ #[derive(Clone, Debug)]
101
+ pub struct Access {
102
+ pub path_id: usize,
103
+ pub dpor_vv: VersionVec,
104
+ pub thread_id: usize,
105
+ pub origin: AccessOrigin,
106
+ }
107
+
108
+ impl Access {
109
+ pub fn new(path_id: usize, dpor_vv: VersionVec, thread_id: usize, origin: AccessOrigin) -> Self {
110
+ Self { path_id, dpor_vv, thread_id, origin }
111
+ }
112
+
113
+ /// Check if this access happens-before the given vector clock.
114
+ /// Paper: e →_E e' (Def 3.2, JACM'17 p.12). When this returns false,
115
+ /// the two events are concurrent and form a race (Def 3.3 p.13-14).
116
+ pub fn happens_before(&self, later_vv: &VersionVec) -> bool {
117
+ self.dpor_vv.partial_le(later_vv)
118
+ }
119
+ }
120
+
121
+ #[cfg(test)]
122
+ mod tests {
123
+ use super::*;
124
+
125
+ #[test]
126
+ fn test_weak_write_weak_read_merge() {
127
+ // WeakWrite conflicts with {Read, Write}; WeakRead conflicts with {Write}.
128
+ // WeakWrite's conflict set is a superset of WeakRead's, so WeakWrite
129
+ // subsumes WeakRead — merging should produce WeakWrite, not Write.
130
+ assert_eq!(AccessKind::WeakWrite.merge(AccessKind::WeakRead), AccessKind::WeakWrite);
131
+ assert_eq!(AccessKind::WeakRead.merge(AccessKind::WeakWrite), AccessKind::WeakWrite);
132
+ }
133
+
134
+ #[test]
135
+ fn test_merge_same_kind() {
136
+ assert_eq!(AccessKind::Read.merge(AccessKind::Read), AccessKind::Read);
137
+ assert_eq!(AccessKind::Write.merge(AccessKind::Write), AccessKind::Write);
138
+ assert_eq!(AccessKind::WeakRead.merge(AccessKind::WeakRead), AccessKind::WeakRead);
139
+ assert_eq!(AccessKind::WeakWrite.merge(AccessKind::WeakWrite), AccessKind::WeakWrite);
140
+ }
141
+
142
+ #[test]
143
+ fn test_read_subsumes_weak_read() {
144
+ assert_eq!(AccessKind::Read.merge(AccessKind::WeakRead), AccessKind::Read);
145
+ assert_eq!(AccessKind::WeakRead.merge(AccessKind::Read), AccessKind::Read);
146
+ }
147
+
148
+ #[test]
149
+ fn test_write_subsumes_everything() {
150
+ assert_eq!(AccessKind::Read.merge(AccessKind::Write), AccessKind::Write);
151
+ assert_eq!(AccessKind::Write.merge(AccessKind::Read), AccessKind::Write);
152
+ assert_eq!(AccessKind::WeakWrite.merge(AccessKind::Read), AccessKind::Write);
153
+ assert_eq!(AccessKind::Read.merge(AccessKind::WeakWrite), AccessKind::Write);
154
+ }
155
+
156
+ #[test]
157
+ fn test_origin_merge_strength_order() {
158
+ assert_eq!(AccessOrigin::PythonMemory.merge(AccessOrigin::IoDirect), AccessOrigin::IoDirect);
159
+ assert_eq!(AccessOrigin::IoDirect.merge(AccessOrigin::PythonMemory), AccessOrigin::IoDirect);
160
+ assert_eq!(AccessOrigin::PythonMemory.merge(AccessOrigin::LockSynthetic), AccessOrigin::LockSynthetic);
161
+ assert_eq!(AccessOrigin::LockSynthetic.merge(AccessOrigin::IoDirect), AccessOrigin::IoDirect);
162
+ }
163
+ }