@cryptotaxi247 / kubo / commits / 85b612698

godeps: update go-uuid

Henry committed Feb 27, 2015 at 13:30 UTC 85b6126983f9d0498a73563e421eb3608661275e
7 files changed +138 -10
Godeps/Godeps.json
+2 -2
@@ -11,8 +11,8 @@
11 },
12 {
13 "ImportPath": "code.google.com/p/go-uuid/uuid",
14 - "Comment": "null-12",
15 - "Rev": "7dda39b2e7d5e265014674c5af696ba4186679e9"
14 + "Comment": "null-15",
15 + "Rev": "35bc42037350f0078e3c974c6ea690f1926603ab"
16 },
17 {
18 "ImportPath": "code.google.com/p/go.crypto/blowfish",
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/LICENSE
+1 -1
@@ -1,4 +1,4 @@
1 -Copyright (c) 2009 Google Inc. All rights reserved.
1 +Copyright (c) 2009,2014 Google Inc. All rights reserved.
2
3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions are
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/json.go new
+30
@@ -0,0 +1,30 @@
1 +// Copyright 2014 Google Inc. All rights reserved.
2 +// Use of this source code is governed by a BSD-style
3 +// license that can be found in the LICENSE file.
4 +
5 +package uuid
6 +
7 +import "errors"
8 +
9 +func (u UUID) MarshalJSON() ([]byte, error) {
10 + if len(u) == 0 {
11 + return []byte(`""`), nil
12 + }
13 + return []byte(`"` + u.String() + `"`), nil
14 +}
15 +
16 +func (u *UUID) UnmarshalJSON(data []byte) error {
17 + if len(data) == 0 || string(data) == `""` {
18 + return nil
19 + }
20 + if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' {
21 + return errors.New("invalid UUID format")
22 + }
23 + data = data[1 : len(data)-1]
24 + uu := Parse(string(data))
25 + if uu == nil {
26 + return errors.New("invalid UUID format")
27 + }
28 + *u = uu
29 + return nil
30 +}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/json_test.go new
+32
@@ -0,0 +1,32 @@
1 +// Copyright 2014 Google Inc. All rights reserved.
2 +// Use of this source code is governed by a BSD-style
3 +// license that can be found in the LICENSE file.
4 +
5 +package uuid
6 +
7 +import (
8 + "encoding/json"
9 + "reflect"
10 + "testing"
11 +)
12 +
13 +var testUUID = Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
14 +
15 +func TestJSON(t *testing.T) {
16 + type S struct {
17 + ID1 UUID
18 + ID2 UUID
19 + }
20 + s1 := S{ID1: testUUID}
21 + data, err := json.Marshal(&s1)
22 + if err != nil {
23 + t.Fatal(err)
24 + }
25 + var s2 S
26 + if err := json.Unmarshal(data, &s2); err != nil {
27 + t.Fatal(err)
28 + }
29 + if !reflect.DeepEqual(&s1, &s2) {
30 + t.Errorf("got %#v, want %#v", s2, s1)
31 + }
32 +}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/seq_test.go new
+66
@@ -0,0 +1,66 @@
1 +// Copyright 2014 Google Inc. All rights reserved.
2 +// Use of this source code is governed by a BSD-style
3 +// license that can be found in the LICENSE file.
4 +
5 +package uuid
6 +
7 +import (
8 + "flag"
9 + "runtime"
10 + "testing"
11 + "time"
12 +)
13 +
14 +// This test is only run when --regressions is passed on the go test line.
15 +var regressions = flag.Bool("regressions", false, "run uuid regression tests")
16 +
17 +// TestClockSeqRace tests for a particular race condition of returning two
18 +// identical Version1 UUIDs. The duration of 1 minute was chosen as the race
19 +// condition, before being fixed, nearly always occured in under 30 seconds.
20 +func TestClockSeqRace(t *testing.T) {
21 + if !*regressions {
22 + t.Skip("skipping regression tests")
23 + }
24 + duration := time.Minute
25 +
26 + done := make(chan struct{})
27 + defer close(done)
28 +
29 + ch := make(chan UUID, 10000)
30 + ncpu := runtime.NumCPU()
31 + switch ncpu {
32 + case 0, 1:
33 + // We can't run the test effectively.
34 + t.Skip("skipping race test, only one CPU detected")
35 + return
36 + default:
37 + runtime.GOMAXPROCS(ncpu)
38 + }
39 + for i := 0; i < ncpu; i++ {
40 + go func() {
41 + for {
42 + select {
43 + case <-done:
44 + return
45 + case ch <- NewUUID():
46 + }
47 + }
48 + }()
49 + }
50 +
51 + uuids := make(map[string]bool)
52 + cnt := 0
53 + start := time.Now()
54 + for u := range ch {
55 + s := u.String()
56 + if uuids[s] {
57 + t.Errorf("duplicate uuid after %d in %v: %s", cnt, time.Since(start), s)
58 + return
59 + }
60 + uuids[s] = true
61 + if time.Since(start) > duration {
62 + return
63 + }
64 + cnt++
65 + }
66 +}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/time.go
+5 -5
@@ -40,15 +40,15 @@ func (t Time) UnixTime() (sec, nsec int64) {
40 }
41
42 // GetTime returns the current Time (100s of nanoseconds since 15 Oct 1582) and
43 -// adjusts the clock sequence as needed. An error is returned if the current
44 -// time cannot be determined.
45 -func GetTime() (Time, error) {
43 +// clock sequence as well as adjusting the clock sequence as needed. An error
44 +// is returned if the current time cannot be determined.
45 +func GetTime() (Time, uint16, error) {
46 defer mu.Unlock()
47 mu.Lock()
48 return getTime()
49 }
50
51 -func getTime() (Time, error) {
51 +func getTime() (Time, uint16, error) {
52 t := timeNow()
53
54 // If we don't have a clock sequence already, set one.
@@ -63,7 +63,7 @@ func getTime() (Time, error) {
63 clock_seq = ((clock_seq + 1) & 0x3fff) | 0x8000
64 }
65 lasttime = now
66 - return Time(now), nil
66 + return Time(now), clock_seq, nil
67 }
68
69 // ClockSequence returns the current clock sequence, generating one if not
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version1.go
+2 -2
@@ -19,7 +19,7 @@ func NewUUID() UUID {
19 SetNodeInterface("")
20 }
21
22 - now, err := GetTime()
22 + now, seq, err := GetTime()
23 if err != nil {
24 return nil
25 }
@@ -34,7 +34,7 @@ func NewUUID() UUID {
34 binary.BigEndian.PutUint32(uuid[0:], time_low)
35 binary.BigEndian.PutUint16(uuid[4:], time_mid)
36 binary.BigEndian.PutUint16(uuid[6:], time_hi)
37 - binary.BigEndian.PutUint16(uuid[8:], clock_seq)
37 + binary.BigEndian.PutUint16(uuid[8:], seq)
38 copy(uuid[10:], nodeID)
39
40 return uuid