Skip to content

Commit

Permalink
Added Results[x].ID = x invariant assertions to every TestingBatch test.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuredoro committed Oct 16, 2021
1 parent 7b8d25e commit dcc323a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,13 @@ func AssertThreadCount(t *testing.T, pool *SpyThreadPool, want int) {
t.Errorf("got %d threads used, want %d", got, want)
}
}

// AssertResultIDInvariant checks that each key in TestingBatch.Results
// equals to the its value`s ID field.
func AssertResultIDInvariant(t *testing.T, b *TestingBatch) {
for k, v := range b.Results {
if k != v.ID {
t.Errorf("invariant violation: %d != Results[%d].ID (which is %d)", k, k, v.ID)
}
}
}
10 changes: 10 additions & 0 deletions testing_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func TestTestingBatch(t *testing.T) {
2: cptest.OK,
}

cptest.AssertResultIDInvariant(t, batch)
cptest.AssertVerdicts(t, batch.Results, want)
cptest.AssertCallCount(t, "proc.Run()", proc.CallCount(), 2)
cptest.AssertThreadCount(t, pool, 2)
Expand Down Expand Up @@ -166,6 +167,7 @@ func TestTestingBatch(t *testing.T) {
2: cptest.OK,
}

cptest.AssertResultIDInvariant(t, batch)
cptest.AssertVerdicts(t, batch.Results, want)
cptest.AssertCallCount(t, "proc.Run()", proc.CallCount(), 2)
cptest.AssertThreadCount(t, pool, 2)
Expand Down Expand Up @@ -211,6 +213,7 @@ func TestTestingBatch(t *testing.T) {
2: cptest.WA,
}

cptest.AssertResultIDInvariant(t, batch)
cptest.AssertVerdicts(t, batch.Results, want)
cptest.AssertCallCount(t, "proc.Run()", proc.CallCount(), 2)
cptest.AssertThreadCount(t, pool, 2)
Expand Down Expand Up @@ -246,6 +249,7 @@ func TestTestingBatch(t *testing.T) {
2: cptest.WA,
}

cptest.AssertResultIDInvariant(t, batch)
cptest.AssertVerdicts(t, batch.Results, want)
cptest.AssertCallCount(t, "proc.Run()", proc.CallCount(), 2)
cptest.AssertThreadCount(t, pool, 2)
Expand Down Expand Up @@ -318,6 +322,7 @@ func TestTestingBatch(t *testing.T) {
5: cptest.IE,
}

cptest.AssertResultIDInvariant(t, batch)
cptest.AssertVerdicts(t, batch.Results, want)
cptest.AssertCallCount(t, "proc.Run()", proc.CallCount(), 5)
cptest.AssertThreadCount(t, pool, 3)
Expand Down Expand Up @@ -381,6 +386,7 @@ func TestTestingBatch(t *testing.T) {
1: 3 * time.Second,
}

cptest.AssertResultIDInvariant(t, batch)
cptest.AssertVerdicts(t, batch.Results, testsWant)
cptest.AssertThreadCount(t, pool, 1)

Expand Down Expand Up @@ -453,6 +459,7 @@ func TestTestingBatch(t *testing.T) {
1: 3 * time.Second,
}

cptest.AssertResultIDInvariant(t, batch)
cptest.AssertVerdicts(t, batch.Results, testsWant)
cptest.AssertThreadCount(t, pool, 1)

Expand Down Expand Up @@ -529,6 +536,7 @@ func TestTestingBatch(t *testing.T) {
2: 3 * time.Second,
}

cptest.AssertResultIDInvariant(t, batch)
cptest.AssertVerdicts(t, batch.Results, testsWant)
cptest.AssertThreadCount(t, pool, 1)

Expand Down Expand Up @@ -606,6 +614,7 @@ func TestTestingBatch(t *testing.T) {
2: 3 * time.Second,
}

cptest.AssertResultIDInvariant(t, batch)
cptest.AssertVerdicts(t, batch.Results, testsWant)
cptest.AssertThreadCount(t, pool, 2)

Expand Down Expand Up @@ -722,6 +731,7 @@ func TestTestingBatch(t *testing.T) {
4: 3 * time.Second,
}

cptest.AssertResultIDInvariant(t, batch)
cptest.AssertVerdicts(t, batch.Results, testsWant)
cptest.AssertThreadCount(t, pool, 2)

Expand Down

0 comments on commit dcc323a

Please sign in to comment.