Commit 70e3c22
committed
Currently, AndroidJUnit4ClassRunner inherits standard JUnit 4 behavior where
timeouts are applied only to the test method itself. If a test timeout is
set (e.g., passed by TradeFed or runner arguments), FailOnTimeout executes
the test method in a separate thread.
Since setup (@before) and teardown (@after) are applied outside this
timeout, they run on the caller thread, causing a thread mismatch. This
prevents ThreadLocal variables initialized in setup from being accessible in
the test.
This CL modifies AndroidJUnit4ClassRunner to apply the timeout to the
combined statement of setup, test, and teardown. This is achieved by:
1. Overriding withAfters to wrap the combined statement in FailOnTimeout.
2. Overriding withPotentialTimeout to be a no-op, preventing double
timeout application.
This ensures all lifecycle methods run on the same thread spawned by the
timeout.
NOTE: Because the timeout now wraps setup and teardown, any time spent in
@before or @after will now count towards the test timeout.
PiperOrigin-RevId: 895547043
1 parent 56d05cb commit 70e3c22
2 files changed
Lines changed: 19 additions & 17 deletions
File tree
- runner/android_junit_runner
- java/androidx/test/internal/runner/junit4
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
Lines changed: 17 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
77 | | - | |
| 76 | + | |
| 77 | + | |
78 | 78 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | 79 | | |
87 | | - | |
88 | | - | |
89 | 80 | | |
90 | 81 | | |
91 | 82 | | |
92 | 83 | | |
93 | | - | |
94 | | - | |
95 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
96 | 90 | | |
| 91 | + | |
| 92 | + | |
97 | 93 | | |
98 | | - | |
99 | | - | |
100 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
0 commit comments