diff -Nru golang-golang-x-time-0.0~git20161028.0.f51c127/CONTRIBUTING.md golang-golang-x-time-0.0+git20200630.3af7569/CONTRIBUTING.md --- golang-golang-x-time-0.0~git20161028.0.f51c127/CONTRIBUTING.md 2017-03-13 07:53:51.000000000 +0000 +++ golang-golang-x-time-0.0+git20200630.3af7569/CONTRIBUTING.md 2020-06-30 17:30:20.000000000 +0000 @@ -4,16 +4,15 @@ It is the work of hundreds of contributors. We appreciate your help! - ## Filing issues When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions: -1. What version of Go are you using (`go version`)? -2. What operating system and processor architecture are you using? -3. What did you do? -4. What did you expect to see? -5. What did you see instead? +1. What version of Go are you using (`go version`)? +2. What operating system and processor architecture are you using? +3. What did you do? +4. What did you expect to see? +5. What did you see instead? General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker. The gophers there will answer or ask you to file an issue if you've tripped over a bug. @@ -23,9 +22,5 @@ Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html) before sending patches. -**We do not accept GitHub pull requests** -(we use [Gerrit](https://code.google.com/p/gerrit/) instead for code review). - Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file. - diff -Nru golang-golang-x-time-0.0~git20161028.0.f51c127/debian/changelog golang-golang-x-time-0.0+git20200630.3af7569/debian/changelog --- golang-golang-x-time-0.0~git20161028.0.f51c127/debian/changelog 2017-06-21 11:43:39.000000000 +0000 +++ golang-golang-x-time-0.0+git20200630.3af7569/debian/changelog 2020-10-06 08:39:13.000000000 +0000 @@ -1,3 +1,20 @@ +golang-golang-x-time (0.0+git20200630.3af7569-1) unstable; urgency=medium + + [ Alexandre Viau ] + * Point Vcs-* urls to salsa.debian.org. + + [ Martín Ferrari ] + * Automated cme fixes. + + [ Dmitry Smirnov ] + * New upstream snapshot. + * Standards-Version: 4.5.0 + * Rules-Requires-Root: no + * Added "watch" file + * DH to version 12 + + -- Dmitry Smirnov Tue, 06 Oct 2020 19:39:13 +1100 + golang-golang-x-time (0.0~git20161028.0.f51c127-2) unstable; urgency=medium * Upload to unstable version already in experimental. diff -Nru golang-golang-x-time-0.0~git20161028.0.f51c127/debian/compat golang-golang-x-time-0.0+git20200630.3af7569/debian/compat --- golang-golang-x-time-0.0~git20161028.0.f51c127/debian/compat 2017-06-21 11:43:39.000000000 +0000 +++ golang-golang-x-time-0.0+git20200630.3af7569/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -9 diff -Nru golang-golang-x-time-0.0~git20161028.0.f51c127/debian/control golang-golang-x-time-0.0+git20200630.3af7569/debian/control --- golang-golang-x-time-0.0~git20161028.0.f51c127/debian/control 2017-06-21 11:43:39.000000000 +0000 +++ golang-golang-x-time-0.0+git20200630.3af7569/debian/control 2020-10-06 08:34:05.000000000 +0000 @@ -1,25 +1,27 @@ Source: golang-golang-x-time -Section: devel -Priority: extra Maintainer: Debian Go Packaging Team Uploaders: Dmitry Smirnov , Martín Ferrari , Tim Potter , Michael Stapelberg , -Build-Depends: debhelper (>= 9), +Section: devel +Testsuite: autopkgtest-pkg-go +Priority: optional +Build-Depends: debhelper-compat (= 12), dh-golang, golang-any, golang-golang-x-net-dev, -Standards-Version: 3.9.8 +Standards-Version: 4.5.0 +Vcs-Browser: https://salsa.debian.org/go-team/packages/golang-golang-x-time +Vcs-Git: https://salsa.debian.org/go-team/packages/golang-golang-x-time.git Homepage: https://golang.org/x/time/rate -Vcs-Browser: https://anonscm.debian.org/cgit/pkg-go/packages/golang-golang-x-time.git -Vcs-Git: https://anonscm.debian.org/git/pkg-go/packages/golang-golang-x-time.git XS-Go-Import-Path: golang.org/x/time +Rules-Requires-Root: no Package: golang-golang-x-time-dev Architecture: all -Depends: ${misc:Depends}, +Depends: golang-golang-x-net-dev, + ${misc:Depends}, ${shlibs:Depends}, - golang-golang-x-net-dev, Description: Go supplementary time packages Supplementary Go time packages. diff -Nru golang-golang-x-time-0.0~git20161028.0.f51c127/debian/copyright golang-golang-x-time-0.0+git20200630.3af7569/debian/copyright --- golang-golang-x-time-0.0~git20161028.0.f51c127/debian/copyright 2017-06-21 11:43:39.000000000 +0000 +++ golang-golang-x-time-0.0+git20200630.3af7569/debian/copyright 2020-10-06 08:38:57.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: time Source: https://github.com/golang/time @@ -7,9 +7,32 @@ License: BSD-3-Clause~Google Files: debian/* -Copyright: 2016 Dmitry Smirnov +Copyright: 2016-2020 Dmitry Smirnov License: BSD-2-Clause +License: BSD-2-Clause + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + ․ + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + ․ + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + ․ + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + License: BSD-3-Clause~Google Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -59,26 +82,3 @@ infringement, or inducement of patent infringement, then any patent rights granted to you under this License for this implementation of Go shall terminate as of the date such litigation is filed. - -License: BSD-2-Clause - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - ․ - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - ․ - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - ․ - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. diff -Nru golang-golang-x-time-0.0~git20161028.0.f51c127/debian/gitlab-ci.yml golang-golang-x-time-0.0+git20200630.3af7569/debian/gitlab-ci.yml --- golang-golang-x-time-0.0~git20161028.0.f51c127/debian/gitlab-ci.yml 1970-01-01 00:00:00.000000000 +0000 +++ golang-golang-x-time-0.0+git20200630.3af7569/debian/gitlab-ci.yml 2020-10-06 08:26:58.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-golang-x-time-0.0~git20161028.0.f51c127/debian/watch golang-golang-x-time-0.0+git20200630.3af7569/debian/watch --- golang-golang-x-time-0.0~git20161028.0.f51c127/debian/watch 1970-01-01 00:00:00.000000000 +0000 +++ golang-golang-x-time-0.0+git20200630.3af7569/debian/watch 2020-10-06 08:29:55.000000000 +0000 @@ -0,0 +1,10 @@ +# https://salsa.debian.org/snippets/96 +# uscan(1) configuration file. +version=4 + +opts="\ +pgpmode=none,\ +mode=git,gitmode=shallow,date=%Y%m%d,pretty=0.0+git%cd.%h,\ +repack,compression=xz,repacksuffix=+dfsg,\ +" https://github.com/golang/time.git \ + heads/master diff -Nru golang-golang-x-time-0.0~git20161028.0.f51c127/go.mod golang-golang-x-time-0.0+git20200630.3af7569/go.mod --- golang-golang-x-time-0.0~git20161028.0.f51c127/go.mod 1970-01-01 00:00:00.000000000 +0000 +++ golang-golang-x-time-0.0+git20200630.3af7569/go.mod 2020-06-30 17:30:20.000000000 +0000 @@ -0,0 +1 @@ +module golang.org/x/time diff -Nru golang-golang-x-time-0.0~git20161028.0.f51c127/rate/rate.go golang-golang-x-time-0.0+git20200630.3af7569/rate/rate.go --- golang-golang-x-time-0.0~git20161028.0.f51c127/rate/rate.go 2017-03-13 07:53:51.000000000 +0000 +++ golang-golang-x-time-0.0+git20200630.3af7569/rate/rate.go 2020-06-30 17:30:20.000000000 +0000 @@ -6,12 +6,11 @@ package rate import ( + "context" "fmt" "math" "sync" "time" - - "golang.org/x/net/context" ) // Limit defines the maximum frequency of some events. @@ -54,10 +53,9 @@ // // The methods AllowN, ReserveN, and WaitN consume n tokens. type Limiter struct { - limit Limit - burst int - mu sync.Mutex + limit Limit + burst int tokens float64 // last is the last time the limiter's tokens field was updated last time.Time @@ -77,6 +75,8 @@ // Burst values allow more events to happen at once. // A zero Burst allows no events, unless limit == Inf. func (lim *Limiter) Burst() int { + lim.mu.Lock() + defer lim.mu.Unlock() return lim.burst } @@ -197,7 +197,7 @@ // ReserveN returns a Reservation that indicates how long the caller must wait before n events happen. // The Limiter takes this Reservation into account when allowing future events. -// ReserveN returns false if n exceeds the Limiter's burst size. +// The returned Reservation’s OK() method returns false if n exceeds the Limiter's burst size. // Usage example: // r := lim.ReserveN(time.Now(), 1) // if !r.OK() { @@ -224,8 +224,13 @@ // canceled, or the expected wait time exceeds the Context's Deadline. // The burst limit is ignored if the rate limit is Inf. func (lim *Limiter) WaitN(ctx context.Context, n int) (err error) { - if n > lim.burst && lim.limit != Inf { - return fmt.Errorf("rate: Wait(n=%d) exceeds limiter's burst %d", n, lim.burst) + lim.mu.Lock() + burst := lim.burst + limit := lim.limit + lim.mu.Unlock() + + if n > burst && limit != Inf { + return fmt.Errorf("rate: Wait(n=%d) exceeds limiter's burst %d", n, burst) } // Check if ctx is already cancelled select { @@ -244,8 +249,12 @@ if !r.ok { return fmt.Errorf("rate: Wait(n=%d) would exceed context deadline", n) } - // Wait - t := time.NewTimer(r.DelayFrom(now)) + // Wait if necessary + delay := r.DelayFrom(now) + if delay == 0 { + return nil + } + t := time.NewTimer(delay) defer t.Stop() select { case <-t.C: @@ -278,6 +287,23 @@ lim.limit = newLimit } +// SetBurst is shorthand for SetBurstAt(time.Now(), newBurst). +func (lim *Limiter) SetBurst(newBurst int) { + lim.SetBurstAt(time.Now(), newBurst) +} + +// SetBurstAt sets a new burst size for the limiter. +func (lim *Limiter) SetBurstAt(now time.Time, newBurst int) { + lim.mu.Lock() + defer lim.mu.Unlock() + + now, _, tokens := lim.advance(now) + + lim.last = now + lim.tokens = tokens + lim.burst = newBurst +} + // reserveN is a helper method for AllowN, ReserveN, and WaitN. // maxFutureReserve specifies the maximum reservation wait duration allowed. // reserveN returns Reservation, not *Reservation, to avoid allocation in AllowN and WaitN. @@ -334,6 +360,7 @@ // advance calculates and returns an updated state for lim resulting from the passage of time. // lim is not changed. +// advance requires that lim.mu is held. func (lim *Limiter) advance(now time.Time) (newNow time.Time, newLast time.Time, newTokens float64) { last := lim.last if now.Before(last) { @@ -367,5 +394,9 @@ // tokensFromDuration is a unit conversion function from a time duration to the number of tokens // which could be accumulated during that duration at a rate of limit tokens per second. func (limit Limit) tokensFromDuration(d time.Duration) float64 { - return d.Seconds() * float64(limit) + // Split the integer and fractional parts ourself to minimize rounding errors. + // See golang.org/issues/34861. + sec := float64(d/time.Second) * float64(limit) + nsec := float64(d%time.Second) * float64(limit) + return sec + nsec/1e9 } diff -Nru golang-golang-x-time-0.0~git20161028.0.f51c127/rate/rate_test.go golang-golang-x-time-0.0+git20200630.3af7569/rate/rate_test.go --- golang-golang-x-time-0.0~git20161028.0.f51c127/rate/rate_test.go 2017-03-13 07:53:51.000000000 +0000 +++ golang-golang-x-time-0.0+git20200630.3af7569/rate/rate_test.go 2020-06-30 17:30:20.000000000 +0000 @@ -2,17 +2,18 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build go1.7 + package rate import ( + "context" "math" "runtime" "sync" "sync/atomic" "testing" "time" - - "golang.org/x/net/context" ) func TestLimit(t *testing.T) { @@ -130,6 +131,15 @@ }) } +// Ensure that tokensFromDuration doesn't produce +// rounding errors by truncating nanoseconds. +// See golang.org/issues/34861. +func TestLimiter_noTruncationErrors(t *testing.T) { + if !NewLimiter(0.7692307692307693, 1).Allow() { + t.Fatal("expected true") + } +} + func TestSimultaneousRequests(t *testing.T) { const ( limit = 1 @@ -164,6 +174,9 @@ } func TestLongRunningQPS(t *testing.T) { + if testing.Short() { + t.Skip("skipping in short mode") + } if runtime.GOOS == "openbsd" { t.Skip("low resolution time.Sleep invalidates test (golang.org/issue/14183)") return @@ -348,6 +361,15 @@ runReserve(t, lim, request{t2, 1, t4, true}) // violates Limit and Burst } +func TestReserveSetBurst(t *testing.T) { + lim := NewLimiter(5, 2) + + runReserve(t, lim, request{t0, 2, t0, true}) + runReserve(t, lim, request{t0, 2, t4, true}) + lim.SetBurstAt(t3, 4) + runReserve(t, lim, request{t0, 4, t9, true}) // violates Limit and Burst +} + func TestReserveSetLimitCancel(t *testing.T) { lim := NewLimiter(5, 2) @@ -443,3 +465,13 @@ } }) } + +func BenchmarkWaitNNoDelay(b *testing.B) { + lim := NewLimiter(Limit(b.N), b.N) + ctx := context.Background() + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + lim.WaitN(ctx, 1) + } +} diff -Nru golang-golang-x-time-0.0~git20161028.0.f51c127/README golang-golang-x-time-0.0+git20200630.3af7569/README --- golang-golang-x-time-0.0~git20161028.0.f51c127/README 2017-03-13 07:53:51.000000000 +0000 +++ golang-golang-x-time-0.0+git20200630.3af7569/README 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -This repository provides supplementary Go time packages. diff -Nru golang-golang-x-time-0.0~git20161028.0.f51c127/README.md golang-golang-x-time-0.0+git20200630.3af7569/README.md --- golang-golang-x-time-0.0~git20161028.0.f51c127/README.md 1970-01-01 00:00:00.000000000 +0000 +++ golang-golang-x-time-0.0+git20200630.3af7569/README.md 2020-06-30 17:30:20.000000000 +0000 @@ -0,0 +1,17 @@ +# Go Time + +This repository provides supplementary Go time packages. + +## Download/Install + +The easiest way to install is to run `go get -u golang.org/x/time`. You can +also manually git clone the repository to `$GOPATH/src/golang.org/x/time`. + +## Report Issues / Send Patches + +This repository uses Gerrit for code changes. To learn how to submit changes to +this repository, see https://golang.org/doc/contribute.html. + +The main issue tracker for the time repository is located at +https://github.com/golang/go/issues. Prefix your issue with "x/time:" in the +subject line, so it is easy to find.