Skip to content
Snippets Groups Projects
Commit 3fab2647 authored by Moritz Langenstein's avatar Moritz Langenstein
Browse files

(ml5717) Added network->frontend correctness test for path

parent 92130ce7
No related branches found
No related tags found
1 merge request!67Benchmark testing
Pipeline #107264 passed
......@@ -322,7 +322,7 @@ describe("drawing app mesh", () => {
let timeout
return new Promise((resolve) => {
// Draw the dot path
// Draw the dot
broadcastListener.callback = (channel, message) => {
expect(channel).toEqual("y-js")
expect(message.message instanceof Uint8Array).toBe(true)
......@@ -338,7 +338,7 @@ describe("drawing app mesh", () => {
.then(
() =>
new Promise((resolve) => {
// Erase the dot path
// Erase the dot
broadcastListener.callback = (channel, message) => {
expect(channel).toEqual("y-js")
expect(message.message instanceof Uint8Array).toBe(true)
......@@ -434,9 +434,6 @@ describe("drawing app mesh", () => {
() =>
new Promise((resolve) => {
// Replay the erase updates
expect(updatePaths).toStrictEqual({ [dotID]: dotDraw })
expect(updateIntervals).toStrictEqual({ [dotID]: {} })
updateRoom.addEventListener(
"removedIntervalsChange",
({ detail: { id, intervals } }) => {
......@@ -561,7 +558,7 @@ describe("drawing app mesh", () => {
if (broadcasts < ITERATIONS) {
const tmpPathID = room.addPath(pathDraw[0])
pathIDs.push(tmpPathID)
for (let i = 1; i < pathDraw.lenth; i++) {
for (let i = 1; i < pathDraw.length; i++) {
room.extendPath(tmpPathID, pathDraw[i])
}
} else if (broadcasts < ITERATIONS * 2) {
......@@ -584,7 +581,7 @@ describe("drawing app mesh", () => {
const tmpPathID = room.addPath(pathDraw[0])
pathIDs.push(tmpPathID)
for (let i = 1; i < pathDraw.lenth; i++) {
for (let i = 1; i < pathDraw.length; i++) {
room.extendPath(tmpPathID, pathDraw[i])
}
}).then(
......@@ -667,7 +664,7 @@ describe("drawing app mesh", () => {
for (let j = 0; j < ITERATIONS; j++) {
const tmpPathID = room.addPath(pathDraw[0])
pathIDs.push(tmpPathID)
for (let i = 1; i < pathDraw.lenth; i++) {
for (let i = 1; i < pathDraw.length; i++) {
room.extendPath(tmpPathID, pathDraw[i])
}
}
......@@ -758,34 +755,50 @@ describe("drawing app mesh", () => {
})
it("communicates a path draw and erase update", () => {
jest.setTimeout(15000)
let pathID
let syncPackets = 0
const addPackets = []
const erasePackets = []
const syncPackets = []
let syncDonePacket = -1
const updatePaths = {}
const updateIntervals = {}
const syncPaths = {}
const syncIntervals = {}
let timeout
return new Promise((resolve) => {
// Draw the path
broadcastListener.callback = (channel, message) => {
expect(channel).toEqual("y-js")
expect(message.message instanceof Uint8Array).toBe(true)
addPackets.push(message)
clearTimeout(timeout)
timeout = setTimeout(() => resolve(), 1000)
}
pathID = room.addPath(pathDraw[0])
for (let i = 1; i < pathDraw.lenth; i++) {
for (let i = 1; i < pathDraw.length; i++) {
room.getPathPoints(pathID)
room.extendPath(pathID, pathDraw[i])
}
})
.then(
() =>
new Promise((resolve) => {
// Erase the path
broadcastListener.callback = (channel, message) => {
expect(channel).toEqual("y-js")
expect(message.message instanceof Uint8Array).toBe(true)
erasePackets.push(message)
clearTimeout(timeout)
timeout = setTimeout(() => resolve(), 1000)
}
......@@ -802,12 +815,13 @@ describe("drawing app mesh", () => {
.then(
() =>
new Promise((resolve) => {
// Request a sync step 2
sendListener.callback = (uid, channel, message) => {
expect(uid).toEqual("moritz")
expect(channel).toEqual("y-js")
expect(message.message instanceof Uint8Array).toBe(true)
syncPackets += 1
syncPackets.push(message)
if (
message.message.length == syncDone.message.length &&
......@@ -816,12 +830,12 @@ describe("drawing app mesh", () => {
) {
expect(syncDonePacket).toEqual(-1)
syncDonePacket = syncPackets
syncDonePacket = syncPackets.length
}
clearTimeout(timeout)
timeout = setTimeout(() => {
expect(syncDonePacket).toEqual(syncPackets)
expect(syncDonePacket).toEqual(syncPackets.length)
resolve()
}, 1000)
......@@ -833,5 +847,131 @@ describe("drawing app mesh", () => {
)(createMessageReceivedEvent(syncStep1))
}),
)
.then(
() =>
new Promise((resolve) => {
// Replay the draw updates
updateRoom.addEventListener(
"addOrUpdatePath",
({ detail: { id, points } }) => {
updatePaths[id] = points
clearTimeout(timeout)
timeout = setTimeout(() => resolve(), 1000)
},
)
updateRoom.addEventListener(
"removedIntervalsChange",
({ detail: { id, intervals } }) => {
updateIntervals[id] = intervals
clearTimeout(timeout)
timeout = setTimeout(() => resolve(), 1000)
},
)
for (const addPacket of addPackets) {
getEventListener(
"update",
"messageReceived",
)(createMessageReceivedEvent(addPacket))
}
}),
)
.then(
() =>
new Promise((resolve) => {
// Check the draw updates
expect(updatePaths).toStrictEqual({ [pathID]: pathDraw })
expect(updateIntervals).toStrictEqual({ [pathID]: {} })
resolve()
}),
)
.then(
() =>
new Promise((resolve) => {
// Replay the erase updates
updateRoom.addEventListener(
"removedIntervalsChange",
({ detail: { id, intervals } }) => {
updateIntervals[id] = intervals
clearTimeout(timeout)
timeout = setTimeout(() => resolve(), 1000)
},
)
for (const erasePacket of erasePackets) {
getEventListener(
"update",
"messageReceived",
)(createMessageReceivedEvent(erasePacket))
}
}),
)
.then(
() =>
new Promise((resolve) => {
// Check the erase updates
expect(updatePaths).toStrictEqual({ [pathID]: pathDraw })
expect(updateIntervals).toStrictEqual({
[pathID]: Object.assign(
{},
new Array(pathDraw.length).fill([[0, 1]]),
),
})
resolve()
}),
)
.then(
() =>
new Promise((resolve) => {
// Replay the synchronisation
syncRoom.addEventListener(
"addOrUpdatePath",
({ detail: { id, points } }) => {
syncPaths[id] = points
clearTimeout(timeout)
timeout = setTimeout(() => resolve(), 1000)
},
)
syncRoom.addEventListener(
"removedIntervalsChange",
({ detail: { id, intervals } }) => {
syncIntervals[id] = intervals
clearTimeout(timeout)
timeout = setTimeout(() => resolve(), 1000)
},
)
for (const syncPacket of syncPackets) {
getEventListener(
"sync",
"messageReceived",
)(createMessageReceivedEvent(syncPacket))
}
}),
)
.then(
() =>
new Promise((resolve) => {
// Check the synchronisation
expect(syncPaths).toStrictEqual({ [pathID]: pathDraw })
expect(syncIntervals).toStrictEqual({
[pathID]: Object.assign(
{},
new Array(pathDraw.length).fill([[0, 1]]),
),
})
resolve()
}),
)
})
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment