Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add two more tests that test uniqueness of v1 UUIDs if times are spec…

…ified, see #24
  • Loading branch information...
commit 77c53e6467ff94279d8ada3ba5c6f63e2616fd35 1 parent 39c3154
@ctavan ctavan authored committed
Showing with 22 additions and 0 deletions.
  1. +22 −0 test/test.js
View
22 test/test.js
@@ -68,6 +68,28 @@ assert(
'IDs created at same msec are different'
);
+// Verify that this node can never produce 2 UUIDs within the same 100ns interval
+var tn = 10;
+var thrown = false;
+try {
+ uuid.v1({msecs: t, nsecs: tn});
+ uuid.v1({msecs: t, nsecs: tn});
+} catch(e) {
+ thrown = true;
+}
+assert(
+ thrown === true,
+ 'IDs created at same 100 nsec throw an error'
+);
+
+// Verify that also a regression by 100ns increments the clockseq
+var uidtn = uuid.v1({msecs: t, nsecs: tn});
+var uidtnb = uuid.v1({msecs: t, nsecs: tn-1});
+assert(
+ parseInt(uidtnb.split('-')[3], 16) - parseInt(uidtn.split('-')[3], 16) === 1,
+ 'IDs created at t and t - 100ns have different clockseq'
+);
+
var id = uuid.v1({
msecs: 1321651533573,
nsecs: 5432,
Please sign in to comment.
Something went wrong with that request. Please try again.