waitForExit polls the output endpoint until the process is no longer running or the context expires.
(t *testing.T, handler http.Handler, id string)
| 174 | // waitForExit polls the output endpoint until the process is |
| 175 | // no longer running or the context expires. |
| 176 | func waitForExit(t *testing.T, handler http.Handler, id string) workspacesdk.ProcessOutputResponse { |
| 177 | t.Helper() |
| 178 | |
| 179 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 180 | defer cancel() |
| 181 | |
| 182 | ticker := time.NewTicker(50 * time.Millisecond) |
| 183 | defer ticker.Stop() |
| 184 | |
| 185 | for { |
| 186 | select { |
| 187 | case <-ctx.Done(): |
| 188 | t.Fatal("timed out waiting for process to exit") |
| 189 | case <-ticker.C: |
| 190 | w := getOutput(t, handler, id) |
| 191 | require.Equal(t, http.StatusOK, w.Code) |
| 192 | |
| 193 | var resp workspacesdk.ProcessOutputResponse |
| 194 | err := json.NewDecoder(w.Body).Decode(&resp) |
| 195 | require.NoError(t, err) |
| 196 | |
| 197 | if !resp.Running { |
| 198 | return resp |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // startAndGetID is a helper that starts a process and returns |
| 205 | // the process ID. |
no test coverage detected