oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipotest
2
3import (
4 "context"
5 "testing"
6 "time"
7
8 "amadan.net/oficina/equipo/internal/equipo"
9 "gorm.io/gorm"
10)
11
12func TestIdlePollDoesNotWrite(t *testing.T) {
13 f := runnerFixtureNew(t, false)
14 before := scalar(t, f.d, "SELECT revision FROM service")
15 ctx, cancel := context.WithTimeout(connectionContext, 350*time.Millisecond)
16 defer cancel()
17 _, _ = f.x.Poll(ctx, f.principal, f.a.ID)
18 if after := scalar(t, f.d, "SELECT revision FROM service"); after != before {
19 t.Fatalf("idle poll committed %d write transactions", after-before)
20 }
21}
22func TestJourneySkipsOldFinishedBeforeLoading(t *testing.T) {
23 f := runnerFixtureNew(t, false)
24 mustSQL(t, f.d, "UPDATE jobs SET state='failed',updated_at=? WHERE id=?", f.clock.Now().AddDate(0, 0, -14).Format(time.RFC3339Nano), f.a.Scope.Job)
25 mustSQL(t, f.d, "UPDATE task_outboxes SET engineering='not-json' WHERE task_id=?", f.a.TaskID)
26 views, err := f.s.Journey(connectionContext, ownerActor)
27 executionMust(t, err)
28 if len(views) != 0 {
29 t.Fatal("loaded old finished task", views)
30 }
31}
32func TestWriteNotifiesOnlyTouchedJob(t *testing.T) {
33 f := runnerFixtureNew(t, false)
34 task, err := f.s.CreateBug(connectionContext, ownerActor, f.project.ID, "second", "second")
35 executionMust(t, err)
36 task, err = f.s.PrepareBug(connectionContext, f.principal, task.ID, task.Revision, bugPrepared(f.connectionFixture))
37 executionMust(t, err)
38 _, err = f.s.StartBug(connectionContext, f.principal, task.ID, task.Revision)
39 executionMust(t, err)
40 n := &taskNotices{}
41 f.s.SetJobNotifier(n)
42 view, err := f.s.TaskView(connectionContext, ownerActor, f.a.TaskID)
43 executionMust(t, err)
44 executionMust(t, f.x.Write(connectionContext, func(tx *gorm.DB) error {
45 return tx.Model(&equipo.Task{}).Where("id=?", f.a.TaskID).Update("description", "changed").Error
46 }))
47 if len(n.topics) != 2 {
48 t.Fatal("write notified unrelated jobs", n.topics)
49 }
50 found := false
51 for _, topic := range n.topics {
52 found = found || topic == view.Topic
53 }
54 if !found {
55 t.Fatal("touched job not notified", n.topics)
56 }
57}
58
59func TestRailCountsUseAggregates(t *testing.T) {
60 f := runnerFixtureNew(t, true)
61 mustSQL(t, f.d, "UPDATE task_outboxes SET engineering='not-json' WHERE task_id=?", f.a.TaskID)
62 counts, err := f.s.SpecialistCounts(connectionContext, ownerActor)
63 executionMust(t, err)
64 if counts["engineering"].Working != 1 || counts["review"].Queued != 1 {
65 t.Fatal("incorrect aggregate counts", counts)
66 }
67}
68
69func TestRailCountsPreserveWeeklyAndUnknownRules(t *testing.T) {
70 t.Run("unknown", func(t *testing.T) {
71 f := bugFixture(t)
72 bugTask(t, f)
73 counts, err := f.s.SpecialistCounts(connectionContext, ownerActor)
74 executionMust(t, err)
75 if counts["engineering"].UsageKnown {
76 t.Fatal("preparation usage reported known")
77 }
78 })
79 t.Run("previous week", func(t *testing.T) {
80 f := runnerFixtureNew(t, true)
81 mustSQL(t, f.d, "UPDATE steps SET state='succeeded' WHERE capability IN ('reproduce','implement')")
82 mustSQL(t, f.d, "UPDATE attempts SET updated_at=?", f.clock.Now().AddDate(0, 0, -14).Format(time.RFC3339Nano))
83 counts, err := f.s.SpecialistCounts(connectionContext, ownerActor)
84 executionMust(t, err)
85 if counts["engineering"].Finished != 0 {
86 t.Fatal("previous week's specialist work counted", counts)
87 }
88 })
89}
90