(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestBeginStepReuseStep(t *testing.T) { |
| 16 | t.Parallel() |
| 17 | |
| 18 | t.Run("reuses handle under ReuseStep", func(t *testing.T) { |
| 19 | t.Parallel() |
| 20 | |
| 21 | chatID := uuid.New() |
| 22 | ownerID := uuid.New() |
| 23 | runID := uuid.New() |
| 24 | t.Cleanup(func() { CleanupStepCounter(runID) }) |
| 25 | |
| 26 | ctrl := gomock.NewController(t) |
| 27 | db := dbmock.NewMockStore(ctrl) |
| 28 | expectDebugLoggingEnabled(t, db, ownerID) |
| 29 | expectCreateStepNumberWithRequestValidity( |
| 30 | t, |
| 31 | db, |
| 32 | runID, |
| 33 | chatID, |
| 34 | 1, |
| 35 | OperationStream, |
| 36 | false, |
| 37 | ) |
| 38 | expectDebugLoggingEnabled(t, db, ownerID) |
| 39 | |
| 40 | svc := NewService(db, testutil.Logger(t), nil) |
| 41 | ctx := ContextWithRun(context.Background(), &RunContext{RunID: runID, ChatID: chatID}) |
| 42 | ctx = ReuseStep(ctx) |
| 43 | opts := RecorderOptions{ChatID: chatID, OwnerID: ownerID} |
| 44 | |
| 45 | firstHandle, firstEnriched := beginStep(ctx, svc, opts, OperationStream, nil) |
| 46 | secondHandle, secondEnriched := beginStep(ctx, svc, opts, OperationStream, nil) |
| 47 | |
| 48 | require.NotNil(t, firstHandle) |
| 49 | require.Same(t, firstHandle, secondHandle) |
| 50 | require.Same(t, firstHandle.stepCtx, secondHandle.stepCtx) |
| 51 | require.Same(t, firstHandle.sink, secondHandle.sink) |
| 52 | require.Equal(t, runID, firstHandle.stepCtx.RunID) |
| 53 | require.Equal(t, chatID, firstHandle.stepCtx.ChatID) |
| 54 | require.Equal(t, int32(1), firstHandle.stepCtx.StepNumber) |
| 55 | require.Equal(t, OperationStream, firstHandle.stepCtx.Operation) |
| 56 | require.NotEqual(t, uuid.Nil, firstHandle.stepCtx.StepID) |
| 57 | |
| 58 | firstStepCtx, ok := StepFromContext(firstEnriched) |
| 59 | require.True(t, ok) |
| 60 | secondStepCtx, ok := StepFromContext(secondEnriched) |
| 61 | require.True(t, ok) |
| 62 | require.Same(t, firstStepCtx, secondStepCtx) |
| 63 | require.Same(t, firstHandle.stepCtx, firstStepCtx) |
| 64 | require.Same(t, attemptSinkFromContext(firstEnriched), attemptSinkFromContext(secondEnriched)) |
| 65 | }) |
| 66 | |
| 67 | t.Run("creates new handles without ReuseStep", func(t *testing.T) { |
| 68 | t.Parallel() |
| 69 | |
| 70 | chatID := uuid.New() |
| 71 | ownerID := uuid.New() |
| 72 | runID := uuid.New() |
nothing calls this directly
no test coverage detected