Skip to content

Commit

Permalink
Revert changes to SyncManager tests
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Hinek <[email protected]>
  • Loading branch information
frankhinek committed Feb 10, 2024
1 parent a18b08d commit 6b73bd3
Showing 1 changed file with 35 additions and 50 deletions.
85 changes: 35 additions & 50 deletions packages/agent/tests/sync-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,53 +76,37 @@ describe('SyncManagerLevel', () => {
await testAgent.closeStorage();
});

// NOTE: from `dwn-sdk-js` `v0.2.10` to `v0.2.16` this test saw a significant increase in time. TODO: investigate
it('syncs multiple records in both directions', async () => {
// create 2 local records.
// create 3 local records.
const localRecords: string[] = [];
const writeResponse1Promise = testAgent.agent.dwnManager.processRequest({
author : alice.did,
target : alice.did,
messageType : 'RecordsWrite',
messageOptions : {
dataFormat: 'text/plain'
},
dataStream: new Blob(['Hello, 1'])
});
const writeResponse2Promise = testAgent.agent.dwnManager.processRequest({
author : alice.did,
target : alice.did,
messageType : 'RecordsWrite',
messageOptions : {
dataFormat: 'text/plain'
},
dataStream: new Blob(['Hello, 2'])
});
localRecords.push(((await writeResponse1Promise).message as RecordsWriteMessage).recordId);
localRecords.push(((await writeResponse2Promise).message as RecordsWriteMessage).recordId);
for (let i = 0; i < 3; i++) {
const writeResponse = await testAgent.agent.dwnManager.processRequest({
author : alice.did,
target : alice.did,
messageType : 'RecordsWrite',
messageOptions : {
dataFormat: 'text/plain'
},
dataStream: new Blob([`Hello, ${i}`])
});

localRecords.push((writeResponse.message as RecordsWriteMessage).recordId);
}

// create 2 remote records
// create 3 remote records
const remoteRecords: string[] = [];
const writeResponse3Promise = testAgent.agent.dwnManager.sendRequest({
author : alice.did,
target : alice.did,
messageType : 'RecordsWrite',
messageOptions : {
dataFormat: 'text/plain'
},
dataStream: new Blob(['Hello, 3'])
});
const writeResponse4Promise = testAgent.agent.dwnManager.sendRequest({
author : alice.did,
target : alice.did,
messageType : 'RecordsWrite',
messageOptions : {
dataFormat: 'text/plain'
},
dataStream: new Blob(['Hello, 4'])
});
remoteRecords.push(((await writeResponse3Promise).message as RecordsWriteMessage).recordId);
remoteRecords.push(((await writeResponse4Promise).message as RecordsWriteMessage).recordId);
for (let i = 0; i < 3; i++) {
let writeResponse = await testAgent.agent.dwnManager.sendRequest({
author : alice.did,
target : alice.did,
messageType : 'RecordsWrite',
messageOptions : {
dataFormat: 'text/plain'
},
dataStream: new Blob([`Hello, ${i}`])
});
remoteRecords.push((writeResponse.message as RecordsWriteMessage).recordId);
}

// query local and check for only local records
let localQueryResponse = await testAgent.agent.dwnManager.processRequest({
Expand All @@ -133,7 +117,7 @@ describe('SyncManagerLevel', () => {
});
let localDwnQueryReply = localQueryResponse.reply as RecordsQueryReply;
expect(localDwnQueryReply.status.code).to.equal(200);
expect(localDwnQueryReply.entries).to.have.length(2);
expect(localDwnQueryReply.entries).to.have.length(3);
let localRecordsFromQuery = localDwnQueryReply.entries?.map(entry => entry.recordId);
expect(localRecordsFromQuery).to.have.members(localRecords);

Expand All @@ -146,7 +130,7 @@ describe('SyncManagerLevel', () => {
});
let remoteDwnQueryReply = remoteQueryResponse.reply as RecordsQueryReply;
expect(remoteDwnQueryReply.status.code).to.equal(200);
expect(remoteDwnQueryReply.entries).to.have.length(2);
expect(remoteDwnQueryReply.entries).to.have.length(3);
let remoteRecordsFromQuery = remoteDwnQueryReply.entries?.map(entry => entry.recordId);
expect(remoteRecordsFromQuery).to.have.members(remoteRecords);

Expand All @@ -168,7 +152,7 @@ describe('SyncManagerLevel', () => {
});
localDwnQueryReply = localQueryResponse.reply as RecordsQueryReply;
expect(localDwnQueryReply.status.code).to.equal(200);
expect(localDwnQueryReply.entries).to.have.length(4);
expect(localDwnQueryReply.entries).to.have.length(6);
localRecordsFromQuery = localDwnQueryReply.entries?.map(entry => entry.recordId);
expect(localRecordsFromQuery).to.have.members([...localRecords, ...remoteRecords]);

Expand All @@ -181,10 +165,11 @@ describe('SyncManagerLevel', () => {
});
remoteDwnQueryReply = remoteQueryResponse.reply as RecordsQueryReply;
expect(remoteDwnQueryReply.status.code).to.equal(200);
expect(remoteDwnQueryReply.entries).to.have.length(4);
expect(remoteDwnQueryReply.entries).to.have.length(6);
remoteRecordsFromQuery = remoteDwnQueryReply.entries?.map(entry => entry.recordId);
expect(remoteRecordsFromQuery).to.have.members([...localRecords, ...remoteRecords]);
}).timeout(3_000);

});

describe('pull()', () => {
it('takes no action if no identities are registered', async () => {
Expand Down Expand Up @@ -380,7 +365,7 @@ describe('SyncManagerLevel', () => {
localDwnQueryReply = queryResponse.reply as RecordsQueryReply;
expect(localDwnQueryReply.status.code).to.equal(200); // Query was successfully executed.
expect(localDwnQueryReply.entries).to.have.length(1); // Record does exist on local DWN.
}).timeout(3_000);
});
});

describe('push()', () => {
Expand Down Expand Up @@ -576,7 +561,7 @@ describe('SyncManagerLevel', () => {
remoteDwnQueryReply = queryResponse.reply as RecordsQueryReply;
expect(remoteDwnQueryReply.status.code).to.equal(200); // Query was successfully executed.
expect(remoteDwnQueryReply.entries).to.have.length(1); // Record does exist on remote DWN.
}).timeout(3_000);
});
});

describe('startSync()', () => {
Expand Down

0 comments on commit 6b73bd3

Please sign in to comment.