Commit 8f83057
authored
Do not initialize non-mocked Dispatchers.Main unnecessarily (#4301)
Before this change, the following could happen on the JVM:
* `kotlinx.coroutines.test` accesses `Dispatchers.Main` before
`setMain` is called.
* `Dispatchers.Main` attempts to initialize *some other* Main
dispatcher in addition to the `kotlinx-coroutines-test` Main
dispatcher, if there is one.
* If the `kotlinx-coroutines-android` artifact is present + its
R8 rules are used to minify the tests, it's illegal to
attempt to fail to create a `Main` dispatcher.
`SUPPORT_MISSING = false` ensures that attempting to create a
Main dispatcher fails immediately, in the call frame that
attempts the creation, not waiting for `Dispatchers.Main` to
be meaningfully used.
In total, `kotlinx-coroutines-test` + `kotlinx-coroutines-android`
+ R8 minification of tests leads to some patterns of
`kotlinx-coroutines-test` usage to crash.
It turns out, though, that the problem originally reported was
simply because of incorrect `kotlinx-coroutines-test` usage.
The error message got improved to guide the programmer in
such scenarios better.
Fixes #42971 parent f8c0304 commit 8f83057
File tree
3 files changed
+43
-13
lines changed- kotlinx-coroutines-test
- common/src/internal
- jvm/src/internal
- ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests
3 files changed
+43
-13
lines changedLines changed: 14 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | | - | |
| 25 | + | |
21 | 26 | | |
22 | 27 | | |
23 | | - | |
| 28 | + | |
24 | 29 | | |
25 | | - | |
| 30 | + | |
26 | 31 | | |
27 | | - | |
| 32 | + | |
28 | 33 | | |
29 | | - | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
36 | | - | |
| 41 | + | |
37 | 42 | | |
38 | 43 | | |
39 | 44 | | |
| |||
Lines changed: 28 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
13 | 28 | | |
14 | 29 | | |
15 | 30 | | |
| |||
24 | 39 | | |
25 | 40 | | |
26 | 41 | | |
27 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
0 commit comments