Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
primitives
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xx network
primitives
Commits
22cc6534
Commit
22cc6534
authored
Apr 2, 2021
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
XX-3169 / Net Time
parent
ed23858b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
netTime/timeNow.go
+20
-0
20 additions, 0 deletions
netTime/timeNow.go
netTime/timeNow_test.go
+40
-0
40 additions, 0 deletions
netTime/timeNow_test.go
with
60 additions
and
0 deletions
netTime/timeNow.go
0 → 100644
+
20
−
0
View file @
22cc6534
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
// Package netTime provides a custom time function that should provide the
// current accurate time used by the network from a custom time service.
package
netTime
import
(
"time"
)
type
NowFunc
func
()
time
.
Time
// Now returns the current accurate time. The function must be set an accurate
// time service that returns the current time with an accuracy of +/- 300 ms.
var
Now
NowFunc
=
time
.
Now
This diff is collapsed.
Click to expand it.
netTime/timeNow_test.go
0 → 100644
+
40
−
0
View file @
22cc6534
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package
netTime
import
(
"testing"
"time"
)
// Happy path: tests that Now() returns time.Now() if it is unset.
func
TestNow
(
t
*
testing
.
T
)
{
expectedTime
:=
time
.
Now
()
.
Round
(
time
.
Millisecond
)
receivedTime
:=
Now
()
.
Round
(
time
.
Millisecond
)
if
!
expectedTime
.
Equal
(
receivedTime
)
{
t
.
Errorf
(
"Returned incorrect time.
\n
expected: %s
\n
received: %s"
,
expectedTime
,
receivedTime
)
}
}
// Happy path: tests that setting Now works.
func
TestNow_Set
(
t
*
testing
.
T
)
{
expectedTime
:=
time
.
Now
()
testNow
:=
func
()
time
.
Time
{
return
expectedTime
}
Now
=
testNow
now
:=
Now
()
if
!
Now
()
.
Equal
(
expectedTime
)
{
t
.
Errorf
(
"Returned incorrect time.
\n
expected: %s
\n
received: %s"
,
expectedTime
,
now
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment