Skip to content
Browse files

Merge pull request #28 from ctavan/exptime

Don't throw 10k error so early, add another test
  • Loading branch information...
2 parents 4110465 + 4eb3e9a commit 2343e92887d26d1db0c09021ca1a50618d9609d7 @broofa committed Jan 2, 2012
Showing with 15 additions and 7 deletions.
  1. +9 −1 test/test.js
  2. +6 −6 uuid.js
View
10 test/test.js
@@ -79,11 +79,19 @@ try {
assert(thrown, 'Exception thrown when > 10K ids created in 1 ms');
// Verify clock regression bumps clockseq
+var uidt = uuid.v1({msecs: TIME});
+var uidtb = uuid.v1({msecs: TIME - 1});
+assert(
+ parseInt(uidtb.split('-')[3], 16) - parseInt(uidt.split('-')[3], 16) === 1,
+ 'Clock regression by msec increments the clockseq'
+);
+
+// Verify clock regression bumps clockseq
var uidtn = uuid.v1({msecs: TIME, nsecs: 10});
var uidtnb = uuid.v1({msecs: TIME, nsecs: 9});
assert(
parseInt(uidtnb.split('-')[3], 16) - parseInt(uidtn.split('-')[3], 16) === 1,
- 'Clock regression increments the clockseq'
+ 'Clock regression by nsec increments the clockseq'
);
// Verify explicit options produce expected id
View
12 uuid.js
@@ -139,12 +139,6 @@
// cycle to simulate higher resolution clock
var nsecs = options.nsecs != null ? options.nsecs : _lastNSecs + 1;
- // Per 4.2.1.2 If generator creates more than one uuid per 100-ns
- // interval, throw an error
- if (nsecs >= 10000) {
- throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
- }
-
// Time since last uuid creation (in msecs)
var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
@@ -160,6 +154,12 @@
nsecs = 0;
}
+ // Per 4.2.1.2 If generator creates more than one uuid per 100-ns
+ // interval, throw an error
+ if (nsecs >= 10000) {
+ throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
+ }
+
_lastMSecs = msecs;
_lastNSecs = nsecs;
_clockseq = clockseq;

0 comments on commit 2343e92

Please sign in to comment.
Something went wrong with that request. Please try again.