diff -Nru golang-github-paulbellamy-ratecounter-0.2.0/avgratecounter_test.go golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/avgratecounter_test.go --- golang-github-paulbellamy-ratecounter-0.2.0/avgratecounter_test.go 2017-07-19 08:59:17.000000000 +0000 +++ golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/avgratecounter_test.go 2018-06-05 06:26:52.000000000 +0000 @@ -9,20 +9,23 @@ interval := 500 * time.Millisecond r := NewAvgRateCounter(interval) - check := func(expected float64) { - val := r.Rate() - if val != expected { - t.Error("Expected ", val, " to equal ", expected) + check := func(expectedRate float64, expectedHits int64) { + rate, hits := r.Rate(), r.Hits() + if rate != expectedRate { + t.Error("Expected rate ", rate, " to equal ", expectedRate) + } + if hits != expectedHits { + t.Error("Expected hits ", hits, " to equal ", expectedHits) } } - check(0) + check(0, 0) r.Incr(1) // counter = 1, hits = 1 - check(1.0) + check(1.0, 1) r.Incr(3) // counter = 4, hits = 2 - check(2.0) + check(2.0, 2) time.Sleep(2 * interval) - check(0) + check(0, 0) } func TestAvgRateCounterAdvanced(t *testing.T) { @@ -30,23 +33,36 @@ almost := 450 * time.Millisecond r := NewAvgRateCounter(interval) - check := func(expected float64) { - val := r.Rate() - if val != expected { - t.Error("Expected ", val, " to equal ", expected) + check := func(expectedRate float64, expectedHits int64) { + rate, hits := r.Rate(), r.Hits() + if rate != expectedRate { + t.Error("Expected rate ", rate, " to equal ", expectedRate) + } + if hits != expectedHits { + t.Error("Expected hits ", hits, " to equal ", expectedHits) } } - check(0) + check(0, 0) r.Incr(1) // counter = 1, hits = 1 - check(1.0) + check(1.0, 1) time.Sleep(interval - almost) r.Incr(3) // counter = 4, hits = 2 - check(2.0) + check(2.0, 2) time.Sleep(almost) - check(3.0) // counter = 3, hits = 1 + check(3.0, 1) // counter = 3, hits = 1 time.Sleep(2 * interval) - check(0) + check(0, 0) +} + +func TestAvgRateCounterMinResolution(t *testing.T) { + defer func() { + if r := recover(); r == nil { + t.Errorf("Resolution < 1 did not panic") + } + }() + + NewAvgRateCounter(500 * time.Millisecond).WithResolution(0) } func TestAvgRateCounterNoResolution(t *testing.T) { @@ -54,28 +70,43 @@ almost := 450 * time.Millisecond r := NewAvgRateCounter(interval).WithResolution(1) - check := func(expected float64) { - val := r.Rate() - if val != expected { - t.Error("Expected ", val, " to equal ", expected) + check := func(expectedRate float64, expectedHits int64) { + rate, hits := r.Rate(), r.Hits() + if rate != expectedRate { + t.Error("Expected rate ", rate, " to equal ", expectedRate) + } + if hits != expectedHits { + t.Error("Expected hits ", hits, " to equal ", expectedHits) } } - check(0) + check(0, 0) r.Incr(1) // counter = 1, hits = 1 - check(1.0) + check(1.0, 1) time.Sleep(interval - almost) r.Incr(3) // counter = 4, hits = 2 - check(2.0) + check(2.0, 2) time.Sleep(almost) - check(0) // counter = 0, hits = 0 + check(0, 0) // counter = 0, hits = 0 time.Sleep(2 * interval) - check(0) + check(0, 0) +} + +func TestAvgRateCounter_String(t *testing.T) { + r := NewAvgRateCounter(1 * time.Second) + if r.String() != "0.00000e+00" { + t.Error("Expected ", r.String(), " to equal ", "0.00000e+00") + } + + r.Incr(1) + if r.String() != "1.00000e+00" { + t.Error("Expected ", r.String(), " to equal ", "1.00000e+00") + } } func TestAvgRateCounter_Incr_ReturnsImmediately(t *testing.T) { interval := 1 * time.Second - r := NewRateCounter(interval) + r := NewAvgRateCounter(interval) start := time.Now() r.Incr(-1) diff -Nru golang-github-paulbellamy-ratecounter-0.2.0/debian/changelog golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/debian/changelog --- golang-github-paulbellamy-ratecounter-0.2.0/debian/changelog 2018-02-06 04:23:28.000000000 +0000 +++ golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/debian/changelog 2018-06-07 04:45:41.000000000 +0000 @@ -1,3 +1,22 @@ +golang-github-paulbellamy-ratecounter (0.2.0+git20170719.a803f0e-3) unstable; urgency=medium + + * Disable unstable tests. + + -- Alexandre Viau Thu, 07 Jun 2018 00:45:41 -0400 + +golang-github-paulbellamy-ratecounter (0.2.0+git20170719.a803f0e-2) unstable; urgency=medium + + * Skip unstable test. + + -- Alexandre Viau Tue, 05 Jun 2018 14:51:34 -0400 + +golang-github-paulbellamy-ratecounter (0.2.0+git20170719.a803f0e-1) unstable; urgency=medium + + * New upstream version. (Closes: #897527) + * Fix insecure-copyright-format-uri. + + -- Alexandre Viau Tue, 05 Jun 2018 02:30:20 -0400 + golang-github-paulbellamy-ratecounter (0.2.0-4) unstable; urgency=medium * Team upload. diff -Nru golang-github-paulbellamy-ratecounter-0.2.0/debian/copyright golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/debian/copyright --- golang-github-paulbellamy-ratecounter-0.2.0/debian/copyright 2018-02-06 04:23:28.000000000 +0000 +++ golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/debian/copyright 2018-06-07 04:45:41.000000000 +0000 @@ -1,4 +1,4 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: ratecounter Source: https://github.com/paulbellamy/ratecounter diff -Nru golang-github-paulbellamy-ratecounter-0.2.0/debian/gitlab-ci.yml golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/debian/gitlab-ci.yml --- golang-github-paulbellamy-ratecounter-0.2.0/debian/gitlab-ci.yml 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/debian/gitlab-ci.yml 2018-06-07 04:45:41.000000000 +0000 @@ -0,0 +1,28 @@ + +# auto-generated, DO NOT MODIFY. +# The authoritative copy of this file lives at: +# https://salsa.debian.org/go-team/ci/blob/master/cmd/ci/gitlabciyml.go + +# TODO: publish under debian-go-team/ci +image: stapelberg/ci2 + +test_the_archive: + artifacts: + paths: + - before-applying-commit.json + - after-applying-commit.json + script: + # Create an overlay to discard writes to /srv/gopath/src after the build: + - "rm -rf /cache/overlay/{upper,work}" + - "mkdir -p /cache/overlay/{upper,work}" + - "mount -t overlay overlay -o lowerdir=/srv/gopath/src,upperdir=/cache/overlay/upper,workdir=/cache/overlay/work /srv/gopath/src" + - "export GOPATH=/srv/gopath" + - "export GOCACHE=/cache/go" + # Build the world as-is: + - "ci-build -exemptions=/var/lib/ci-build/exemptions.json > before-applying-commit.json" + # Copy this package into the overlay: + - "GBP_CONF_FILES=:debian/gbp.conf gbp buildpackage --git-no-pristine-tar --git-ignore-branch --git-ignore-new --git-export-dir=/tmp/export --git-no-overlay --git-tarball-dir=/nonexistant --git-cleaner=/bin/true --git-builder='dpkg-buildpackage -S -d --no-sign'" + - "pgt-gopath -dsc /tmp/export/*.dsc" + # Rebuild the world: + - "ci-build -exemptions=/var/lib/ci-build/exemptions.json > after-applying-commit.json" + - "ci-diff before-applying-commit.json after-applying-commit.json" diff -Nru golang-github-paulbellamy-ratecounter-0.2.0/debian/rules golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/debian/rules --- golang-github-paulbellamy-ratecounter-0.2.0/debian/rules 2018-02-06 04:23:28.000000000 +0000 +++ golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/debian/rules 2018-06-07 04:45:41.000000000 +0000 @@ -2,3 +2,6 @@ %: dh $@ --buildsystem=golang --with=golang + +override_dh_auto_test: + # Tests are very unstable with high load. diff -Nru golang-github-paulbellamy-ratecounter-0.2.0/.gitignore golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/.gitignore --- golang-github-paulbellamy-ratecounter-0.2.0/.gitignore 2017-07-19 08:59:17.000000000 +0000 +++ golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/.gitignore 2018-06-05 06:26:52.000000000 +0000 @@ -22,3 +22,4 @@ *.exe *.sw? +coverage.txt diff -Nru golang-github-paulbellamy-ratecounter-0.2.0/ratecounter_test.go golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/ratecounter_test.go --- golang-github-paulbellamy-ratecounter-0.2.0/ratecounter_test.go 2017-07-19 08:59:17.000000000 +0000 +++ golang-github-paulbellamy-ratecounter-0.2.0+git20170719.a803f0e/ratecounter_test.go 2018-06-05 06:26:52.000000000 +0000 @@ -142,6 +142,16 @@ check(0) } +func TestRateCounterMinResolution(t *testing.T) { + defer func() { + if r := recover(); r == nil { + t.Errorf("Resolution < 1 did not panic") + } + }() + + NewRateCounter(500 * time.Millisecond).WithResolution(0) +} + func TestRateCounterNoResolution(t *testing.T) { interval := 500 * time.Millisecond tenth := 50 * time.Millisecond @@ -174,6 +184,18 @@ check(0) } +func TestRateCounter_String(t *testing.T) { + r := NewRateCounter(1 * time.Second) + if r.String() != "0" { + t.Error("Expected ", r.String(), " to equal ", "0") + } + + r.Incr(1) + if r.String() != "1" { + t.Error("Expected ", r.String(), " to equal ", "1") + } +} + func TestRateCounter_Incr_ReturnsImmediately(t *testing.T) { interval := 1 * time.Second r := NewRateCounter(interval)