Răsfoiți Sursa

fix off by 1 error in key sharding

Henry Oswald 5 ani în urmă
părinte
comite
46b389e8b3

+ 1 - 1
services/real-time/app/js/DocumentUpdaterManager.js

@@ -89,7 +89,7 @@ const DocumentUpdaterManager = {
   },
 
   _getPendingUpdateListKey() {
-    const shard = _.random(0, settings.pendingUpdateListShardCount)
+    const shard = _.random(0, settings.pendingUpdateListShardCount - 1)
     if (shard === 0) {
       return 'pending-updates-list'
     } else {

+ 6 - 1
services/real-time/test/unit/js/DocumentUpdaterManagerTests.js

@@ -407,16 +407,21 @@ describe('DocumentUpdaterManager', function () {
       this.keys = _.unique(keys)
     })
     it('should return normal pending updates key', function () {
-      const key = this.DocumentUpdaterManager._getPendingUpdateListKey()
       _.contains(this.keys, 'pending-updates-list').should.equal(true)
     })
 
     it('should return pending-updates-list-n keys', function () {
       _.contains(this.keys, 'pending-updates-list-1').should.equal(true)
       _.contains(this.keys, 'pending-updates-list-3').should.equal(true)
+      _.contains(this.keys, 'pending-updates-list-9').should.equal(true)
     })
+
     it('should not include pending-updates-list-0 key', function () {
       _.contains(this.keys, 'pending-updates-list-0').should.equal(false)
     })
+
+    it('should not include maximum as pendingUpdateListShardCount value', function () {
+      _.contains(this.keys, 'pending-updates-list-10').should.equal(false)
+    })
   })
 })