1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
11 "git.arvados.org/arvados.git/sdk/go/arvados"
12 "git.arvados.org/arvados.git/sdk/go/arvadostest"
13 check "gopkg.in/check.v1"
16 var _ = check.Suite(&activityPeriodSuite{})
18 type activityPeriodSuite struct{}
20 // The important thing is that, even when daylight savings time is
21 // making things difficult, the current period ends in the future.
22 func (*activityPeriodSuite) TestPeriod(c *check.C) {
23 toronto, err := time.LoadLocation("America/Toronto")
24 c.Assert(err, check.IsNil)
26 format := "2006-01-02 15:04:05 MST"
27 dststartday, err := time.ParseInLocation(format, "2022-03-13 00:00:00 EST", toronto)
28 c.Assert(err, check.IsNil)
29 dstendday, err := time.ParseInLocation(format, "2022-11-06 00:00:00 EDT", toronto)
30 c.Assert(err, check.IsNil)
32 for _, period := range []time.Duration{
39 for offset := time.Duration(0); offset < 48*time.Hour; offset += 3 * time.Minute {
40 t := dststartday.Add(offset)
41 end := alignedPeriod(t, period)
42 c.Check(end.After(t), check.Equals, true, check.Commentf("period %v offset %v", period, offset))
44 t = dstendday.Add(offset)
45 end = alignedPeriod(t, period)
46 c.Check(end.After(t), check.Equals, true, check.Commentf("period %v offset %v", period, offset))
51 func (s *CollectionSuite) TestLogActivity(c *check.C) {
52 starttime := time.Now()
53 s.localdb.activeUsersLock.Lock()
54 s.localdb.activeUsersReset = starttime
55 s.localdb.activeUsersLock.Unlock()
56 for i := 0; i < 2; i++ {
57 logthreshold := time.Now()
58 _, err := s.localdb.CollectionCreate(s.userctx, arvados.CreateOptions{
59 Attrs: map[string]interface{}{
60 "name": "test collection",
62 EnsureUniqueName: true,
64 c.Assert(err, check.IsNil)
66 err = s.db.QueryRowContext(s.ctx, `select uuid from logs where object_uuid = $1 and event_at > $2`, arvadostest.ActiveUserUUID, logthreshold.UTC()).Scan(&uuid)
68 c.Check(err, check.IsNil)
69 c.Check(uuid, check.HasLen, 27)
71 c.Check(err, check.Equals, sql.ErrNoRows)