Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with MoveBefore #80

Closed
jeemyeong opened this issue Sep 8, 2020 · 1 comment · Fixed by #89
Closed

Bug with MoveBefore #80

jeemyeong opened this issue Sep 8, 2020 · 1 comment · Fixed by #89
Labels
bug 🐞 Something isn't working
Projects

Comments

@jeemyeong
Copy link
Contributor

What happened:

Cannot pass test code

Yorkie Can handle concurrent moveBefore operations FAILED
        AssertionError: expected '{"k1":[1,2,0]}' to equal '{"k1":[2,1,0]}'

What you expected to happen:

PASSED

How to reproduce it (as minimally and precisely as possible):
When I edit test code like below

      d1.update((root) => {
        const next = root['k1'].getElementByIndex(0);
        const item = root['k1'].getElementByIndex(2);
        root['k1'].moveBefore(next.getID(), item.getID());
        assert.equal('{"k1":[2,0,1]}', root.toJSON());
      });
      await c1.sync();
      d1.update((root) => {
        const next = root['k1'].getElementByIndex(0);
        const item = root['k1'].getElementByIndex(2);
        root['k1'].moveBefore(next.getID(), item.getID());
        assert.equal('{"k1":[1,2,0]}', root.toJSON());
      });

from

it('Can handle concurrent moveBefore operations', async function () {
await withTwoClientsAndDocuments(async (c1, d1, c2, d2) => {
d1.update((root) => {
root['k1'] = [0, 1, 2];
assert.equal('{"k1":[0,1,2]}', root.toJSON());
});
await c1.sync();
await c2.sync();
assert.equal(d1.toJSON(), d2.toJSON());
d1.update((root) => {
const next = root['k1'].getElementByIndex(0);
const item = root['k1'].getElementByIndex(2);
root['k1'].moveBefore(next.getID(), item.getID());
assert.equal('{"k1":[2,0,1]}', root.toJSON());
});
d2.update((root) => {
const next = root['k1'].getElementByIndex(1);
const item = root['k1'].getElementByIndex(2);
root['k1'].moveBefore(next.getID(), item.getID());
assert.equal('{"k1":[0,2,1]}', root.toJSON());
});
await c1.sync();
await c2.sync();
await c1.sync();
}, this.test.title);
});

Anything else we need to know?:

I am researching moveAfter functions and I cannot found the purpose of some codes.

this.insertAfter(prevNode.getCreatedAt(), node.getValue());

public insertAfter(prevCreatedAt: TimeTicket, value: JSONElement): void {
const prevNode = this.findByCreatedAt(prevCreatedAt, value.getCreatedAt());

When I was debugging some codes,
prevNode from const prevNode = this.findByCreatedAt(prevCreatedAt, value.getCreatedAt()); was not same with as I expected.

I cannot catch the purpose of this code.

private findByCreatedAt(
prevCreatedAt: TimeTicket,
createdAt: TimeTicket,
): RGATreeListNode {
let node = this.nodeMapByCreatedAt.get(prevCreatedAt.toIDString());
if (!node) {
logger.fatal(`cant find the given node: ${prevCreatedAt.toIDString()}`);
}
while (node.getNext() && node.getNext().getCreatedAt().after(createdAt)) {
node = node.getNext();
}
return node;
}

Environment:

  • Operating system: (Mac OS 10.15.6)
  • Browser and version: Chrome Headless 85.0.4183.83
  • Yorkie version (use yorkie version): 0.0.12
  • Yorkie JS SDK version: 0.0.9
@hackerwins hackerwins added the bug 🐞 Something isn't working label Sep 9, 2020
@jeemyeong
Copy link
Contributor Author

I caught the purposed of the findByCreatedAt method. (which has two arguments).

I will try to fix this issue.

@jeemyeong jeemyeong mentioned this issue Sep 11, 2020
2 tasks
@hackerwins hackerwins mentioned this issue Sep 20, 2020
2 tasks
@hackerwins hackerwins added this to Done in v0.1 Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
No open projects
v0.1
Done
Development

Successfully merging a pull request may close this issue.

2 participants