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

mendersoftware / mender-server / 1900805255

01 Jul 2025 05:31PM UTC coverage: 66.222% (+0.5%) from 65.694%
1900805255

Pull #774

gitlab-ci

web-flow
chore: bump pillow from 11.2.1 to 11.3.0 in /backend/tests

Bumps [pillow](https://github.com/python-pillow/Pillow) from 11.2.1 to 11.3.0.
- [Release notes](https://github.com/python-pillow/Pillow/releases)
- [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst)
- [Commits](https://github.com/python-pillow/Pillow/compare/11.2.1...11.3.0)

---
updated-dependencies:
- dependency-name: pillow
  dependency-version: 11.3.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #774: chore: bump pillow from 11.2.1 to 11.3.0 in /backend/tests

29486 of 44526 relevant lines covered (66.22%)

1.44 hits per line

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

0.0
/backend/pkg/rate/limit.go
1
package rate
2

3
import (
4
        "context"
5
        "time"
6

7
        "golang.org/x/time/rate"
8
)
9

10
// Limiter implements a rate limiting interface based on golang.org/x/time/rate
11
// but extending the interface with the ability to expose internal errors.
12
type Limiter interface {
13
        Reserve(ctx context.Context) (Reservation, error)
14
        Tokens(ctx context.Context) (uint64, error)
15
}
16

17
// Reservation is a point-in-time reservation of a ratelimit token. If the token
18
// is approved OK return true, otherways Delay will return the duration for next
19
// token(s) to become available. While Tokens return the number of available
20
// tokens after the reservation.
21
type Reservation interface {
22
        OK() bool
23
        Delay() time.Duration
24
        Tokens() uint64
25
}
26

27
type limiter rate.Limiter
28

29
func NewLimiter(limit int, interval time.Duration) Limiter {
×
30
        return (*limiter)(rate.NewLimiter(rate.Every(interval/time.Duration(limit)), limit))
×
31
}
×
32

33
func (lim *limiter) Reserve(context.Context) (Reservation, error) {
×
34
        now := time.Now()
×
35
        goLimiter := (*rate.Limiter)(lim)
×
36
        res := &reservation{
×
37
                reservation: goLimiter.ReserveN(now, 1),
×
38
                time:        now,
×
39
        }
×
40
        if res.OK() {
×
41
                res.tokens = uint64(goLimiter.TokensAt(now))
×
42
        }
×
43
        return res, nil
×
44
}
45

46
func (lim *limiter) Tokens(context.Context) (uint64, error) {
×
47
        goLimiter := (*rate.Limiter)(lim)
×
48
        if tokens := goLimiter.Tokens(); tokens > 0 {
×
49
                return uint64(tokens), nil
×
50
        }
×
51
        return 0, nil
×
52
}
53

54
type reservation struct {
55
        time        time.Time
56
        tokens      uint64
57
        reservation *rate.Reservation
58
}
59

60
func (r *reservation) OK() bool {
×
61
        return r.Delay() == 0
×
62
}
×
63

64
func (r *reservation) Delay() time.Duration {
×
65
        return r.reservation.DelayFrom(r.time)
×
66
}
×
67

68
func (r *reservation) Tokens() uint64 {
×
69
        return r.tokens
×
70
}
×
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

© 2025 Coveralls, Inc