• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

murex / TCR / 11775639932

11 Nov 2024 09:20AM UTC coverage: 90.441% (+0.04%) from 90.406%
11775639932

push

github

mengdaming
Bump go version from 1.23.1 to 1.23.3

5251 of 5806 relevant lines covered (90.44%)

5496.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.29
/src/timer/mob_turn_countdown.go
1
/*
2
Copyright (c) 2024 Murex
3

4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights
7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
10

11
The above copyright notice and this permission notice shall be included in all
12
copies or substantial portions of the Software.
13

14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
SOFTWARE.
21
*/
22

23
package timer
24

25
import (
26
        "github.com/murex/tcr/report"
27
        "github.com/murex/tcr/report/timer_event"
28
        "github.com/murex/tcr/runmode"
29
        "time"
30
)
31

32
// NewMobTurnCountdown creates a PeriodicReminder that starts when entering driver mode, and
33
// then sends a countdown message periodically until the driver turn expires, after which it
34
// sends a message notifying the end of driver's turn.
35
// If the mode does not require a mob timer, this function returns nil
36
func NewMobTurnCountdown(mode runmode.RunMode, timeout time.Duration) *PeriodicReminder {
15✔
37
        if !mode.IsMultiRole() {
24✔
38
                return nil
9✔
39
        }
9✔
40
        tickPeriod := findBestTickPeriodFor(timeout)
6✔
41
        return NewPeriodicReminder(timeout, tickPeriod,
6✔
42
                func(ctx ReminderContext) {
21✔
43
                        switch ctx.eventType {
15✔
44
                        case startEvent:
3✔
45
                                reportTimerEvent(ctx, timer_event.TriggerStart, timeout)
3✔
46
                        case periodicEvent:
3✔
47
                                if ctx.remaining > 0 {
6✔
48
                                        reportTimerEvent(ctx, timer_event.TriggerCountdown, timeout)
3✔
49
                                } else {
3✔
50
                                        reportTimerEvent(ctx, timer_event.TriggerTimeout, timeout)
×
51
                                }
×
52
                        case interruptEvent:
3✔
53
                                reportTimerEvent(ctx, timer_event.TriggerStop, timeout)
3✔
54
                        case timeoutEvent:
6✔
55
                                reportTimerEvent(ctx, timer_event.TriggerTimeout, timeout)
6✔
56
                        }
57
                },
58
        )
59
}
60

61
func reportTimerEvent(ctx ReminderContext, trigger timer_event.Trigger, timeout time.Duration) {
15✔
62
        report.PostTimerEvent(trigger, timeout, ctx.elapsed, ctx.remaining)
15✔
63
}
15✔
64

65
func findBestTickPeriodFor(timeout time.Duration) time.Duration {
24✔
66
        const oneSecond = 1 * time.Second   //nolint:revive
24✔
67
        const tenSeconds = 10 * time.Second //nolint:revive
24✔
68
        const oneMinute = 1 * time.Minute   //nolint:revive
24✔
69

24✔
70
        if timeout <= tenSeconds {
33✔
71
                return oneSecond
9✔
72
        }
9✔
73
        if timeout <= oneMinute {
21✔
74
                return tenSeconds
6✔
75
        }
6✔
76
        return defaultTickPeriod
9✔
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc