Skip to content

Commit 8fe8844

Browse files
committed
metrics: use testTime instead of now, and make testTime increment.
Merge with the metrics commit on the next rebase.
1 parent 420f18a commit 8fe8844

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/crypto/tls/handshake_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"strconv"
2121
"strings"
2222
"sync"
23+
"sync/atomic"
2324
"testing"
2425
"time"
2526
)
@@ -429,10 +430,17 @@ func fromHex(s string) []byte {
429430
return b
430431
}
431432

432-
// testTime is 2016-10-20T17:32:09.000Z, which is within the validity period of
433-
// [testRSACertificate], [testRSACertificateIssuer], [testRSA2048Certificate],
434-
// [testRSA2048CertificateIssuer], and [testECDSACertificate].
435-
var testTime = func() time.Time { return time.Unix(1476984729, 0) }
433+
// Returns currentTestTime and then increments by a second.
434+
var testTime = func() time.Time { return time.Unix(currentTestTime.Add(1), 0) }
435+
436+
// currentTestTime is initially 2016-10-20T17:32:09.000Z, which is well within
437+
// the validity period of [testRSACertificate], [testRSACertificateIssuer],
438+
// [testRSA2048Certificate], [testRSA2048CertificateIssuer], and [testECDSACertificate].
439+
var currentTestTime atomic.Int64
440+
441+
func init() {
442+
currentTestTime.Store(1476984729)
443+
}
436444

437445
var testRSACertificate = fromHex("3082024b308201b4a003020102020900e8f09d3fe25beaa6300d06092a864886f70d01010b0500301f310b3009060355040a1302476f3110300e06035504031307476f20526f6f74301e170d3136303130313030303030305a170d3235303130313030303030305a301a310b3009060355040a1302476f310b300906035504031302476f30819f300d06092a864886f70d010101050003818d0030818902818100db467d932e12270648bc062821ab7ec4b6a25dfe1e5245887a3647a5080d92425bc281c0be97799840fb4f6d14fd2b138bc2a52e67d8d4099ed62238b74a0b74732bc234f1d193e596d9747bf3589f6c613cc0b041d4d92b2b2423775b1c3bbd755dce2054cfa163871d1e24c4f31d1a508baab61443ed97a77562f414c852d70203010001a38193308190300e0603551d0f0101ff0404030205a0301d0603551d250416301406082b0601050507030106082b06010505070302300c0603551d130101ff0402300030190603551d0e041204109f91161f43433e49a6de6db680d79f60301b0603551d230414301280104813494d137e1631bba301d5acab6e7b30190603551d1104123010820e6578616d706c652e676f6c616e67300d06092a864886f70d01010b0500038181009d30cc402b5b50a061cbbae55358e1ed8328a9581aa938a495a1ac315a1a84663d43d32dd90bf297dfd320643892243a00bccf9c7db74020015faad3166109a276fd13c3cce10c5ceeb18782f16c04ed73bbb343778d0c1cf10fa1d8408361c94c722b9daedb4606064df4c1b33ec0d1bd42d4dbfe3d1360845c21d33be9fae7")
438446

src/crypto/tls/metrics_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"io"
1111
"io/ioutil"
1212
"testing"
13-
"time"
1413
)
1514

1615
type testTimingInfo struct {
@@ -106,7 +105,7 @@ func TestTLS13HandshakeTiming(t *testing.T) {
106105
const serverName = "example.golang"
107106

108107
baseConfig := &Config{
109-
Time: time.Now,
108+
Time: testTime,
110109
Rand: zeroSource{},
111110
Certificates: make([]Certificate, 1),
112111
MaxVersion: VersionTLS13,

0 commit comments

Comments
 (0)