Skip to content

Commit

Permalink
Unflake key iteration test
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrichina committed Feb 16, 2024
1 parent 1c6f6c5 commit a0b64aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 2 additions & 0 deletions storage/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class RedisStorage {
do {
const [newIterator, keys] = await this.redisClient.hscan(Buffer.from(`k:${DATA_SCOPE}:${contractId}`), iterator, 'MATCH', keyPattern, 'COUNT', SCAN_COUNT);
console.log('keys', keys.map(k => k.toString('utf8')), newIterator.toString('utf8'))
// TODO: Need to dedup keys?
// NOTE: See SCAN command guarantees: https://redis.io/commands/scan/
const newData = await Promise.all(keys.map(async storageKey => {
const compKey = Buffer.concat([Buffer.from(`${DATA_SCOPE}:${contractId}:`), storageKey]);
const dataBlockHeight = await this.getLatestDataBlockHeight(compKey, blockHeight);
Expand Down
5 changes: 2 additions & 3 deletions test/rest-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,9 @@ test('view contract data with iterator', async t => {
t.is(res.status, 200);

const { data, iterator } = res.body;
t.equal(data.length, 1000);

const { data: data2, iterator: iterator2 } = (await request.get(`/account/test.near/data/*?iterator=${iterator}`)).body;
t.equal(data2.length, 7);
// NOTE: There is no guarantee on how the data is cut into chunks, so we just check that all data is there
// See https://redis.io/commands/scan/ for more details

t.deepEqual([...data, ...data2].sort((a, b) => a[0].localeCompare(b[0])), BIG_DATA.concat([
[ '8charkey', 'test-value-updated' ],
Expand Down

0 comments on commit a0b64aa

Please sign in to comment.