test(uploads): jobSink forwards the tracker's timestamp to the store (#51)
The worker fake ignored the heartbeat time, so the store-boundary half of the app-clock fix had no assertion. Found by the PR #58 review. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
package uploads
|
||||||
|
|
||||||
|
// Observes what jobSink hands the store: the heartbeat's timestamp is the one the tracker
|
||||||
|
// stamped (its application clock), not a second reading taken here (#51).
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.d-ma.be/mathias/tapir/internal/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
type atStore struct{ beatAt, saveAt time.Time }
|
||||||
|
|
||||||
|
func (*atStore) StartTranscribing(context.Context, string, string) error { return nil }
|
||||||
|
func (*atStore) CompleteUpload(context.Context, string, string, domain.Transcription) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (*atStore) FailUpload(context.Context, string, string, domain.UploadErrorKind) error { return nil }
|
||||||
|
func (s *atStore) SaveProgress(_ context.Context, _, _ string, _ []domain.ProgressStep, at time.Time) error {
|
||||||
|
s.saveAt = at
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (s *atStore) Heartbeat(_ context.Context, _, _ string, at time.Time) error {
|
||||||
|
s.beatAt = at
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJobSink_ForwardsTheTrackersTimestampToTheStoreUnchanged(t *testing.T) {
|
||||||
|
st := &atStore{}
|
||||||
|
sink := jobSink{st: st, userID: "u", id: "i"}
|
||||||
|
stamp := time.Date(2020, 1, 2, 3, 4, 5, 0, time.UTC)
|
||||||
|
|
||||||
|
if err := sink.Beat(context.Background(), stamp); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := sink.SaveProgress(context.Background(), nil, stamp); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !st.beatAt.Equal(stamp) {
|
||||||
|
t.Errorf("heartbeat reached the store stamped %v, want the tracker's %v", st.beatAt, stamp)
|
||||||
|
}
|
||||||
|
if !st.saveAt.Equal(stamp) {
|
||||||
|
t.Errorf("progress save reached the store stamped %v, want the tracker's %v", st.saveAt, stamp)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user