Skip to content

Commit

Permalink
Fix test and update Travis config
Browse files Browse the repository at this point in the history
  • Loading branch information
leonelquinteros committed Jul 30, 2019
1 parent c686494 commit 9c08a6e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
language: go

go:
- 1.5
- 1.6
- 1.7
- 1.9
- "1.10"
- "1.11"
- "1.12"
- tip

script: go test -v -race -coverprofile=coverage.txt -covermode=atomic .
Expand Down
5 changes: 3 additions & 2 deletions id.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import (
)

var localID [9]byte
var defaultID = [9]byte{'D', 'e', 'f', 'a', 'u', 'l', 't', 'I', 'D'}

// Initializes the value for the local process run identifier
func init() {
buf, err := GetBytes(9)
if err != nil {
localID = [9]byte{'D', 'e', 'f', 'a', 'u', 'l', 't', 'I', 'D'}
localID = defaultID
} else {
_, err = io.ReadFull(bytes.NewBuffer(buf), localID[:])
if err != nil {
localID = [9]byte{'D', 'e', 'f', 'a', 'u', 'l', 't', 'I', 'D'}
localID = defaultID
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gorand
import (
"encoding/hex"
"testing"
"time"
)

func TestID(t *testing.T) {
Expand All @@ -17,13 +18,16 @@ func TestID(t *testing.T) {
}

func TestIDOrder(t *testing.T) {
ids := make([][64]byte, 100000)
for i := 0; i < 100000; i++ {
ids := make([][64]byte, 10000)
for i := 0; i < 10000; i++ {
id, err := ID()
if err != nil {
t.Fatal(err)
}
ids[i] = id

// Force time change for testing purposes
time.Sleep(1 * time.Millisecond)
}

for i, v := range ids {
Expand Down

0 comments on commit 9c08a6e

Please sign in to comment.