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