| 1036 | } |
| 1037 | |
| 1038 | func TestRecordingMultipleSimultaneous(t *testing.T) { |
| 1039 | t.Parallel() |
| 1040 | |
| 1041 | logger := slogtest.Make(t, nil) |
| 1042 | fake := &fakeDesktop{ |
| 1043 | startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080}, |
| 1044 | } |
| 1045 | api := agentdesktop.NewAPI(logger, fake, nil) |
| 1046 | defer api.Close() |
| 1047 | |
| 1048 | handler := api.Routes() |
| 1049 | |
| 1050 | // Start two recordings with different IDs. |
| 1051 | for _, id := range []string{testRecIDConcurrentA, testRecIDConcurrentB} { |
| 1052 | body, err := json.Marshal(map[string]string{"recording_id": id}) |
| 1053 | require.NoError(t, err) |
| 1054 | rr := httptest.NewRecorder() |
| 1055 | req := httptest.NewRequest(http.MethodPost, "/recording/start", bytes.NewReader(body)) |
| 1056 | handler.ServeHTTP(rr, req) |
| 1057 | require.Equal(t, http.StatusOK, rr.Code) |
| 1058 | } |
| 1059 | |
| 1060 | // Stop both and verify each returns its own data. |
| 1061 | expected := map[string][]byte{ |
| 1062 | testRecIDConcurrentA: []byte("fake-mp4-data-" + testRecIDConcurrentA + "-1"), |
| 1063 | testRecIDConcurrentB: []byte("fake-mp4-data-" + testRecIDConcurrentB + "-2"), |
| 1064 | } |
| 1065 | for _, id := range []string{testRecIDConcurrentA, testRecIDConcurrentB} { |
| 1066 | body, err := json.Marshal(map[string]string{"recording_id": id}) |
| 1067 | require.NoError(t, err) |
| 1068 | rr := httptest.NewRecorder() |
| 1069 | req := httptest.NewRequest(http.MethodPost, "/recording/stop", bytes.NewReader(body)) |
| 1070 | handler.ServeHTTP(rr, req) |
| 1071 | require.Equal(t, http.StatusOK, rr.Code) |
| 1072 | parts := parseMultipartParts(t, rr.Header().Get("Content-Type"), rr.Body.Bytes()) |
| 1073 | assert.Equal(t, expected[id], parts["video/mp4"]) |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | func TestRecordingStartMalformedBody(t *testing.T) { |
| 1078 | t.Parallel() |