8784: Fix test for latest firefox.
[arvados.git] / services / keep-balance / collection_test.go
1 package main
2
3 import (
4         "sync"
5         "time"
6
7         "git.curoverse.com/arvados.git/sdk/go/arvados"
8         check "gopkg.in/check.v1"
9 )
10
11 //  TestIdenticalTimestamps ensures EachCollection returns the same
12 //  set of collections for various page sizes -- even page sizes so
13 //  small that we get entire pages full of collections with identical
14 //  timestamps and exercise our gettingExactTimestamp cases.
15 func (s *integrationSuite) TestIdenticalTimestamps(c *check.C) {
16         // pageSize==0 uses the default (large) page size.
17         pageSizes := []int{0, 2, 3, 4, 5}
18         got := make([][]string, len(pageSizes))
19         var wg sync.WaitGroup
20         for trial, pageSize := range pageSizes {
21                 wg.Add(1)
22                 go func(trial, pageSize int) {
23                         defer wg.Done()
24                         streak := 0
25                         longestStreak := 0
26                         var lastMod time.Time
27                         sawUUID := make(map[string]bool)
28                         err := EachCollection(&s.config.Client, pageSize, func(c arvados.Collection) error {
29                                 got[trial] = append(got[trial], c.UUID)
30                                 if c.ModifiedAt == nil {
31                                         return nil
32                                 }
33                                 if sawUUID[c.UUID] {
34                                         // dup
35                                         return nil
36                                 }
37                                 sawUUID[c.UUID] = true
38                                 if lastMod == *c.ModifiedAt {
39                                         streak++
40                                         if streak > longestStreak {
41                                                 longestStreak = streak
42                                         }
43                                 } else {
44                                         streak = 0
45                                         lastMod = *c.ModifiedAt
46                                 }
47                                 return nil
48                         }, nil)
49                         c.Check(err, check.IsNil)
50                         c.Check(longestStreak > 25, check.Equals, true)
51                 }(trial, pageSize)
52         }
53         wg.Wait()
54         for trial := 1; trial < len(pageSizes); trial++ {
55                 c.Check(got[trial], check.DeepEquals, got[0])
56         }
57 }