1
0
mirror of https://github.com/golang/go synced 2024-10-03 19:21:21 -06:00
Commit Graph

21 Commits

Author SHA1 Message Date
Russ Cox
f69991c17d context: make DeadlineExceeded implement net.Error
It already implemented the Timeout method,
but implementing the full net.Error is more convenient.

Fixes #14238 (again).

Change-Id: Ia87f897f0f35bcb49865e2355964049227951ca6
Reviewed-on: https://go-review.googlesource.com/30370
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-05 15:53:04 +00:00
Matt Layher
c5f064ee49 context: discourage use of basic types as keys in WithValue
Fixes #17302

Change-Id: I375d5d4f2714ff415542f4fe56a548e53c5e8ba6
Reviewed-on: https://go-review.googlesource.com/30134
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-09-30 21:30:29 +00:00
Carlos C
1161a19c1e context: add examples
Add function level examples to the package.

Partially addresses #16360

Change-Id: I7162aed4e4a969743c19b79c9ffaf9217d2c1c08
Reviewed-on: https://go-review.googlesource.com/26930
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-09-09 22:50:41 +00:00
Jack Lindamood
39382793d3 context: reduce memory usage of context tree
Modifies context package to use map[]struct{} rather than map[]bool,
since the map is intended as a set object.  Also adds Benchmarks to
the context package switching between different types of root nodes
and a tree with different depths.

Included below are bytes deltas between the old and new code, using
these benchmarks.

benchmark                                                       old bytes     new bytes     delta
BenchmarkContextCancelTree/depth=1/Root=Background-8            176           176           +0.00%
BenchmarkContextCancelTree/depth=1/Root=OpenCanceler-8          560           544           -2.86%
BenchmarkContextCancelTree/depth=1/Root=ClosedCanceler-8        352           352           +0.00%
BenchmarkContextCancelTree/depth=10/Root=Background-8           3632          3488          -3.96%
BenchmarkContextCancelTree/depth=10/Root=OpenCanceler-8         4016          3856          -3.98%
BenchmarkContextCancelTree/depth=10/Root=ClosedCanceler-8       1936          1936          +0.00%
BenchmarkContextCancelTree/depth=100/Root=Background-8          38192         36608         -4.15%
BenchmarkContextCancelTree/depth=100/Root=OpenCanceler-8        38576         36976         -4.15%
BenchmarkContextCancelTree/depth=100/Root=ClosedCanceler-8      17776         17776         +0.00%
BenchmarkContextCancelTree/depth=1000/Root=Background-8         383792        367808        -4.16%
BenchmarkContextCancelTree/depth=1000/Root=OpenCanceler-8       384176        368176        -4.16%
BenchmarkContextCancelTree/depth=1000/Root=ClosedCanceler-8     176176        176176        +0.00%

Change-Id: I699ad704d9f7b461214e1651d24941927315b525
Reviewed-on: https://go-review.googlesource.com/25270
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2016-09-09 02:30:22 +00:00
Brad Fitzpatrick
298791a94a all: use time.Until where applicable
Updates #14595

Change-Id: Idf60b3004c7a0ebb59dd48389ab62c854069e09f
Reviewed-on: https://go-review.googlesource.com/28073
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-30 01:23:46 +00:00
Jaana Burcu Dogan
ab9137dd24 context: test WithCancel with canceled parent
Change-Id: I32079cc12cfffb8520f0073a8b5119705dc0cd1b
Reviewed-on: https://go-review.googlesource.com/27401
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-19 20:25:12 +00:00
Jack Lindamood
8876061149 context: add test for WithDeadline in the past
Adds a test case for calling context.WithDeadline() where the deadline
exists in the past.  This change increases the code coverage of the
context package.

Change-Id: Ib486bf6157e779fafd9dab2b7364cdb5a06be36e
Reviewed-on: https://go-review.googlesource.com/25007
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Run-TryBot: Sameer Ajmani <sameer@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-07-26 14:53:38 +00:00
Alan Donovan
fc12bb2636 context: cancel the context in ExampleWithTimeout, with explanation
Fixes #16230

Change-Id: Ibb10234a6c3ab8bd0cfd93c2ebe8cfa66f80f6b0
Reviewed-on: https://go-review.googlesource.com/24682
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-06-30 19:56:02 +00:00
Sameer Ajmani
e4dc7f1ed2 context: update documentation on cancelation and go vet check.
Also replace double spaces after periods with single spaces.

Change-Id: Iedaea47595c5ce64e7e8aa3a368f36d49061c555
Reviewed-on: https://go-review.googlesource.com/24431
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-06-24 19:21:21 +00:00
Sameer Ajmani
c4692da923 context: document how to release resources associated with Contexts.
Some users don't realize that creating a Context with a CancelFunc
attaches a subtree to the parent, and that that subtree is not released
until the CancelFunc is called or the parent is canceled.  Make this
clear early in the package docs, so that people learning about this
package have the right conceptual model.

Change-Id: I7c77a546c19c3751dd1f3a5bc827ad106dd1afbf
Reviewed-on: https://go-review.googlesource.com/24090
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-06-15 00:30:46 +00:00
Kenny Grant
04acd625d7 context: fix typo in comments
Change-Id: I41310ec88c889fda79d80eaf4a742a1000284f60
Reviewed-on: https://go-review.googlesource.com/23591
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-06-01 00:09:32 +00:00
Brad Fitzpatrick
dc4427f372 context: make DeadlineExceeded have a Timeout method
Fixes #14238

Change-Id: I1538bfb5cfa63e36a89df1f6eb9f5a0dcafb6ce5
Reviewed-on: https://go-review.googlesource.com/23256
Reviewed-by: Dave Cheney <dave@cheney.net>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-19 23:09:16 +00:00
Shenghou Ma
0960c7c7eb context: use https in docs
Change-Id: I9354712768702e3b083c77f30165a34cb414d686
Reviewed-on: https://go-review.googlesource.com/22810
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-05-05 18:31:23 +00:00
Brad Fitzpatrick
c884f6594a context: produce a nicer panic message for a nil WithValue key
Change-Id: I2e8ae403622ba7131cadaba506100d79613183f1
Reviewed-on: https://go-review.googlesource.com/22601
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-04-29 03:20:51 +00:00
Brad Fitzpatrick
87bca88c70 context: fix doc typo
Fixes #15449

Change-Id: I8d84d076a05c56694b48f7b84f572b1a6524f522
Reviewed-on: https://go-review.googlesource.com/22493
Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-04-27 02:58:54 +00:00
Brad Fitzpatrick
501ddf7189 context: attempt to deflake timing tests
Passes on OpenBSD now when running it with -count=500.

Presumably this will also fix the same problems seen on FreeBSD and
Windows.

Fixes #15158

Change-Id: I86451c901613dfa5ecff0c2ecc516527a3c011b3
Reviewed-on: https://go-review.googlesource.com/21840
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-04-11 23:15:02 +00:00
Brad Fitzpatrick
bd72497666 context: document that WithValue's key must be comparable
Also, check it and explode earlier, rather than cryptic failures later.

Change-Id: I319a425f60e2bc9d005a187fbdbd153faa96411c
Reviewed-on: https://go-review.googlesource.com/21799
Reviewed-by: Andrew Gerrand <adg@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
2016-04-11 01:52:10 +00:00
Brad Fitzpatrick
59d186832b context: disable more flaky tests on openbsd
Updates #15158

Change-Id: Icb3788152a7a5a9b0d56ea38da46d770ffdce413
Reviewed-on: https://go-review.googlesource.com/21763
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-04-08 18:39:11 +00:00
Brad Fitzpatrick
e2c09749af context: mark more tests as flaky on OpenBSD
Updates #15158

Change-Id: I53e9e68d36efbf52736822e6caa047cfff501283
Reviewed-on: https://go-review.googlesource.com/21653
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-07 17:49:26 +00:00
Brad Fitzpatrick
2cefd12a1b net, runtime: skip flaky tests on OpenBSD
Flaky tests are a distraction and cover up real problems.

File bugs instead and mark them as flaky.

This moves the net/http flaky test flagging mechanism to internal/testenv.

Updates #15156
Updates #15157
Updates #15158

Change-Id: I0e561cd2a09c0dec369cd4ed93bc5a2b40233dfe
Reviewed-on: https://go-review.googlesource.com/21614
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-06 19:28:24 +00:00
Brad Fitzpatrick
9db7ef5614 context: add the context package from golang.org/x/net/context
This copies the golang.org/x/net/context package to the standard library.

It is imported from the x/net repo's git rev 1d9fd3b8333e (the most
recent modified to x/net/context as of 2016-03-07).

The corresponding change to x/net/context is in https://golang.org/cl/20347

Updates #14660

Change-Id: Ida14b1b7e115194d6218d9ac614548b9f41641cc
Reviewed-on: https://go-review.googlesource.com/20346
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-05 00:08:50 +00:00