Skip to content

Commit 13aa9e3

Browse files
authored
Merge pull request #371 from boostcampwm-2022/dev
Deploy: 5์ฃผ์ฐจ day3 ๋ฐฐํฌ
2 parents 3979e40 + e452690 commit 13aa9e3

30 files changed

+495
-279
lines changed

โ€Ž@wabinar/api-types/auth.tsโ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import { User } from './user';
2+
13
export interface PostLoginBody {
24
code: string;
35
}
6+
7+
export interface LoginResBody {
8+
user: User;
9+
}

โ€Ž@wabinar/api-types/user.tsโ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { Workspace } from './workspace';
22

3+
export type User = {
4+
id: number;
5+
name: string;
6+
avatarUrl: string;
7+
};
8+
39
export interface GetWorkspaceParams {
410
id: number;
511
}

โ€Ž@wabinar/crdt/convergence.test.tsโ€Ž

Lines changed: 0 additions & 83 deletions
This file was deleted.

โ€Ž@wabinar/crdt/crdt.test.tsโ€Ž

Lines changed: 0 additions & 34 deletions
This file was deleted.

โ€Ž@wabinar/crdt/linked-list.tsโ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ export default class LinkedList {
111111

112112
const prevNode = this.findByIndex(index - 1);
113113

114-
if (!prevNode.next) return null;
114+
if (!prevNode.next) throw new Error();
115115

116116
const targetNode = this.getNode(prevNode.next);
117117

118-
if (!targetNode) return null;
118+
if (!targetNode) throw new Error();
119119

120120
this.deleteNode(targetNode.id);
121121
prevNode.next = targetNode.next;
@@ -215,7 +215,7 @@ export default class LinkedList {
215215

216216
spread(): string[] {
217217
let node: Node | null = this.getHeadNode();
218-
let result = [];
218+
let result: string[] = [];
219219

220220
while (node) {
221221
result.push(node.value);
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import CRDT from '../index';
2+
import LinkedList from '../linked-list';
3+
import { convergenceCheck, remoteInsertThroughSocket } from './utils';
4+
5+
let ์›ํฌ, ์ฃผ์˜, ๋„ํ›ˆ, ์„ธ์˜, remoteSites;
6+
7+
const arrange = () => {
8+
const ์›ํฌremotes = [์›ํฌ.localInsert(-1, '๋…•'), ์›ํฌ.localInsert(-1, '์•ˆ')];
9+
10+
[์ฃผ์˜, ๋„ํ›ˆ, ์„ธ์˜].forEach((๋‚˜) => {
11+
์›ํฌremotes.forEach((op) => remoteInsertThroughSocket(๋‚˜, op));
12+
});
13+
};
14+
15+
describe('Convergence', () => {
16+
beforeEach(() => {
17+
์›ํฌ = new CRDT(1, new LinkedList());
18+
์ฃผ์˜ = new CRDT(2, new LinkedList());
19+
๋„ํ›ˆ = new CRDT(3, new LinkedList());
20+
์„ธ์˜ = new CRDT(4, new LinkedList());
21+
22+
remoteSites = [์›ํฌ, ์ฃผ์˜, ๋„ํ›ˆ, ์„ธ์˜];
23+
24+
arrange();
25+
});
26+
27+
it('ํ•˜๋‚˜์˜ site์—์„œ ์‚ฝ์ž…', () => {
28+
arrange();
29+
30+
convergenceCheck(remoteSites);
31+
});
32+
33+
it('์—ฌ๋Ÿฌ site์—์„œ ๊ฐ™์€ ์œ„์น˜์— ์‚ฝ์ž…', () => {
34+
const ๋„ํ›ˆremote = ๋„ํ›ˆ.localInsert(0, '์™ญ');
35+
const ์„ธ์˜remote = ์„ธ์˜.localInsert(0, '?');
36+
37+
remoteInsertThroughSocket(๋„ํ›ˆ, ์„ธ์˜remote);
38+
remoteInsertThroughSocket(์„ธ์˜, ๋„ํ›ˆremote);
39+
40+
[์›ํฌ, ์ฃผ์˜].forEach((๋‚˜) => {
41+
remoteInsertThroughSocket(๋‚˜, ๋„ํ›ˆremote);
42+
remoteInsertThroughSocket(๋‚˜, ์„ธ์˜remote);
43+
});
44+
45+
convergenceCheck(remoteSites);
46+
});
47+
48+
it('์—ฌ๋Ÿฌ site์—์„œ ๋‹ค๋ฅธ ์œ„์น˜์— ์‚ฝ์ž…', () => {
49+
const ์›ํฌremote = ์›ํฌ.localInsert(0, '๋„ค');
50+
const ์ฃผ์˜remote = ์ฃผ์˜.localInsert(1, '!');
51+
52+
remoteInsertThroughSocket(์›ํฌ, ์ฃผ์˜remote);
53+
remoteInsertThroughSocket(์ฃผ์˜, ์›ํฌremote);
54+
55+
[๋„ํ›ˆ, ์„ธ์˜].forEach((๋‚˜) => {
56+
remoteInsertThroughSocket(๋‚˜, ์›ํฌremote);
57+
remoteInsertThroughSocket(๋‚˜, ์ฃผ์˜remote);
58+
});
59+
60+
convergenceCheck(remoteSites);
61+
});
62+
63+
it('์—ฌ๋Ÿฌ site์—์„œ ๊ฐ™์€ ์œ„์น˜ ์‚ญ์ œ', () => {
64+
const ๋„ํ›ˆremote = ๋„ํ›ˆ.localDelete(0);
65+
const ์„ธ์˜remote = ์„ธ์˜.localDelete(0);
66+
67+
๋„ํ›ˆ.remoteDelete(์„ธ์˜remote);
68+
์„ธ์˜.remoteDelete(๋„ํ›ˆremote);
69+
70+
[์›ํฌ, ์ฃผ์˜].forEach((๋‚˜) => {
71+
๋‚˜.remoteDelete(์„ธ์˜remote);
72+
๋‚˜.remoteDelete(๋„ํ›ˆremote);
73+
});
74+
75+
convergenceCheck(remoteSites);
76+
});
77+
78+
it('์—ฌ๋Ÿฌ site์—์„œ ๋‹ค๋ฅธ ์œ„์น˜ ์‚ญ์ œ', () => {
79+
const ์›ํฌremote = ์›ํฌ.localDelete(0);
80+
const ์ฃผ์˜remote = ์ฃผ์˜.localDelete(1);
81+
82+
์›ํฌ.remoteDelete(์ฃผ์˜remote);
83+
์ฃผ์˜.remoteDelete(์›ํฌremote);
84+
85+
[๋„ํ›ˆ, ์„ธ์˜].forEach((๋‚˜) => {
86+
๋‚˜.remoteDelete(์›ํฌremote);
87+
๋‚˜.remoteDelete(์ฃผ์˜remote);
88+
});
89+
90+
convergenceCheck(remoteSites);
91+
});
92+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import CRDT from '../index';
2+
import LinkedList from '../linked-list';
3+
4+
describe('CRDT Local operations', () => {
5+
let ๋‚˜;
6+
7+
beforeEach(() => {
8+
const initialStructure = new LinkedList();
9+
๋‚˜ = new CRDT(1, initialStructure);
10+
});
11+
12+
describe('localInsert()', () => {
13+
it('head ์œ„์น˜ ์‚ฝ์ž…์— ์„ฑ๊ณตํ•œ๋‹ค.', () => {
14+
// act
15+
๋‚˜.localInsert(-1, '๋…•');
16+
๋‚˜.localInsert(-1, '์•ˆ');
17+
18+
// assert
19+
expect(๋‚˜.read()).toEqual('์•ˆ๋…•');
20+
});
21+
22+
it('tail ์œ„์น˜ ์‚ฝ์ž…์— ์„ฑ๊ณตํ•œ๋‹ค.', () => {
23+
// act
24+
๋‚˜.localInsert(-1, '์•ˆ');
25+
๋‚˜.localInsert(0, '๋…•');
26+
27+
// assert
28+
expect(๋‚˜.read()).toEqual('์•ˆ๋…•');
29+
});
30+
31+
it('์—†๋Š” ์œ„์น˜์— ์‚ฝ์ž… ์‹œ๋„ ์‹œ ์—๋Ÿฌ๋ฅผ ๋˜์ง„๋‹ค.', () => {
32+
// arrange
33+
๋‚˜.localInsert(-1, '์•ˆ');
34+
35+
// act & assert
36+
expect(() => ๋‚˜.localInsert(1, '๋…•')).toThrow();
37+
});
38+
});
39+
40+
describe('localDelete()', () => {
41+
it('tail ์œ„์น˜ ์‚ญ์ œ์— ์„ฑ๊ณตํ•œ๋‹ค.', () => {
42+
// arrange
43+
๋‚˜.localInsert(-1, '์•ˆ');
44+
๋‚˜.localInsert(0, '๋…•');
45+
46+
// act
47+
๋‚˜.localDelete(1);
48+
49+
// assert
50+
expect(๋‚˜.read()).toEqual('์•ˆ');
51+
});
52+
53+
it('์—†๋Š” ์œ„์น˜์— ์‚ญ์ œ ์‹œ๋„ ์‹œ ์—๋Ÿฌ๋ฅผ ๋˜์ง„๋‹ค.', () => {
54+
// arrange
55+
๋‚˜.localInsert(-1, '์•ˆ');
56+
57+
// act & assert
58+
expect(() => ๋‚˜.localDelete(1)).toThrow();
59+
});
60+
});
61+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import CRDT from '../index';
2+
import LinkedList from '../linked-list';
3+
import { remoteInsertThroughSocket } from './utils';
4+
5+
describe('Exceptions', () => {
6+
let ๋„ํ›ˆ, ํ˜ธ๋‘”, remoteSites;
7+
8+
beforeEach(() => {
9+
๋„ํ›ˆ = new CRDT(1, new LinkedList());
10+
ํ˜ธ๋‘” = new CRDT(2, new LinkedList());
11+
12+
remoteSites = [๋„ํ›ˆ, ํ˜ธ๋‘”];
13+
14+
const ๋„ํ›ˆremotes = [
15+
๋„ํ›ˆ.localInsert(-1, '๋…•'),
16+
๋„ํ›ˆ.localInsert(-1, '์•ˆ'),
17+
];
18+
๋„ํ›ˆremotes.forEach((op) => remoteInsertThroughSocket(ํ˜ธ๋‘”, op));
19+
});
20+
21+
it('์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ธ๋ฑ์Šค์— localInsert', () => {
22+
expect(() => ๋„ํ›ˆ.localInsert(100, '.')).toThrow();
23+
});
24+
25+
it('์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋…ธ๋“œ ๋’ค์— remoteInsert', () => {
26+
const ๋„ํ›ˆremotes = [
27+
๋„ํ›ˆ.localInsert(1, '.'),
28+
๋„ํ›ˆ.localInsert(2, '.'),
29+
๋„ํ›ˆ.localInsert(3, '.'),
30+
];
31+
32+
// ์—ฐ์†๋œ remote operation ์ˆœ์„œ๊ฐ€ ์„ž์ด๋Š” ์ผ€์ด์Šค
33+
expect(() => ํ˜ธ๋‘”.remoteInsert(๋„ํ›ˆremotes[1])).toThrow();
34+
});
35+
36+
it('local์—์„œ ์‚ญ์ œ๋œ ๋…ธ๋“œ ๋’ค์— ์‚ฝ์ž…', () => {
37+
const ๋„ํ›ˆremote = ๋„ํ›ˆ.localInsert(0, '!');
38+
const ํ˜ธ๋‘”remote = ํ˜ธ๋‘”.localDelete(0);
39+
40+
expect(() => ํ˜ธ๋‘”.remoteInsert(๋„ํ›ˆremote)).toThrow();
41+
});
42+
});

0 commit comments

Comments
ย (0)