shardFromEnv reads the shard configuration from the environment. When DEVBOX_TEST_SHARD_TOTAL is unset (or 1), all scripts run on a single runner. Otherwise each runner sets DEVBOX_TEST_SHARD_INDEX (0-based) and runs only the scripts assigned to it.
(t *testing.T)
| 87 | // Otherwise each runner sets DEVBOX_TEST_SHARD_INDEX (0-based) and runs only the |
| 88 | // scripts assigned to it. |
| 89 | func shardFromEnv(t *testing.T) shard { |
| 90 | total := 1 |
| 91 | if v := os.Getenv("DEVBOX_TEST_SHARD_TOTAL"); v != "" { |
| 92 | n, err := strconv.Atoi(v) |
| 93 | require.NoError(t, err, "invalid DEVBOX_TEST_SHARD_TOTAL=%q", v) |
| 94 | require.Positive(t, n, "DEVBOX_TEST_SHARD_TOTAL must be positive") |
| 95 | total = n |
| 96 | } |
| 97 | |
| 98 | index := 0 |
| 99 | if v := os.Getenv("DEVBOX_TEST_SHARD_INDEX"); v != "" { |
| 100 | n, err := strconv.Atoi(v) |
| 101 | require.NoError(t, err, "invalid DEVBOX_TEST_SHARD_INDEX=%q", v) |
| 102 | index = n |
| 103 | } |
| 104 | require.GreaterOrEqual(t, index, 0, "DEVBOX_TEST_SHARD_INDEX must be >= 0") |
| 105 | require.Less(t, index, total, "DEVBOX_TEST_SHARD_INDEX must be < DEVBOX_TEST_SHARD_TOTAL") |
| 106 | return shard{index: index, total: total} |
| 107 | } |
| 108 | |
| 109 | // includes reports whether the item at position i (in a deterministic ordering) |
| 110 | // belongs to this shard. Round-robin assignment keeps heavy scripts spread |
no outgoing calls
no test coverage detected