Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 90 additions & 23 deletions packages/framework/presence/src/test/batching.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Licensed under the MIT License.
*/

import { strict as assert } from "node:assert";

import { EventAndErrorTrackingLogger } from "@fluidframework/test-utils/internal";
import { describe, it, after, afterEach, before, beforeEach } from "mocha";
import { useFakeTimers, type SinonFakeTimers } from "sinon";
Expand All @@ -23,7 +25,8 @@ describe("Presence", () => {
describe("batching", () => {
let runtime: MockEphemeralRuntime;
let logger: EventAndErrorTrackingLogger;
const initialTime = 1000;
const initialTime = 500;
const testStartTime = 1010;
let clock: SinonFakeTimers;
let presence: PresenceWithNotifications;

Expand All @@ -35,8 +38,6 @@ describe("Presence", () => {
logger = new EventAndErrorTrackingLogger();
runtime = new MockEphemeralRuntime(logger);

// Note that while the initialTime is set to 1000, the prepareConnectedPresence call advances
// it to 1010 so all tests start at that time.
clock.setSystemTime(initialTime);

// Set up the presence connection.
Expand All @@ -47,6 +48,12 @@ describe("Presence", () => {
clock,
logger,
).presence;

// Note that while the initialTime was set to 500, the prepareConnectedPresence call advances
// it. Set a consistent start time for all tests.
const deltaToStart = testStartTime - clock.now;
assert(deltaToStart >= 0);
clock.tick(deltaToStart);
});

afterEach(() => {
Expand All @@ -72,7 +79,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"s:name:testStateWorkspace": {
Expand All @@ -99,7 +110,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"s:name:testStateWorkspace": {
Expand All @@ -126,7 +141,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"s:name:testStateWorkspace": {
Expand Down Expand Up @@ -168,7 +187,7 @@ describe("Presence", () => {
assertFinalExpectations(runtime, logger);
});

it("sets timer for default allowableUpdateLatency", async () => {
it("sets timer for default allowableUpdateLatencyMs", async () => {
runtime.signalsExpected.push([
{
type: "Pres:DatastoreUpdate",
Expand All @@ -180,7 +199,7 @@ describe("Presence", () => {
"clientToSessionId": {
[connectionId2]: {
"rev": 0,
"timestamp": 1000,
"timestamp": initialTime,
"value": attendeeId2,
},
},
Expand Down Expand Up @@ -215,7 +234,7 @@ describe("Presence", () => {
clock.tick(100); // Time is now 1110
});

it("batches signals sent within default allowableUpdateLatency", async () => {
it("batches signals sent within default allowableUpdateLatencyMs", async () => {
runtime.signalsExpected.push(
[
{
Expand All @@ -226,7 +245,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"s:name:testStateWorkspace": {
Expand All @@ -253,7 +276,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"s:name:testStateWorkspace": {
Expand Down Expand Up @@ -315,7 +342,7 @@ describe("Presence", () => {
clock.tick(30); // Time is now 1180
});

it("batches signals sent within a specified allowableUpdateLatency", async () => {
it("batches signals sent within a specified allowableUpdateLatencyMs", async () => {
runtime.signalsExpected.push(
[
{
Expand All @@ -326,7 +353,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"s:name:testStateWorkspace": {
Expand All @@ -353,7 +384,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"s:name:testStateWorkspace": {
Expand Down Expand Up @@ -424,7 +459,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"s:name:testStateWorkspace": {
Expand Down Expand Up @@ -460,7 +499,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"s:name:testStateWorkspace": {
Expand Down Expand Up @@ -530,7 +573,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"s:name:testStateWorkspace": {
Expand Down Expand Up @@ -566,7 +613,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"s:name:testStateWorkspace": {
Expand Down Expand Up @@ -632,7 +683,7 @@ describe("Presence", () => {
"clientToSessionId": {
[connectionId2]: {
"rev": 0,
"timestamp": 1000,
"timestamp": initialTime,
"value": attendeeId2,
},
},
Expand Down Expand Up @@ -713,7 +764,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"n:name:testNotificationWorkspace": {
Expand All @@ -739,7 +794,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"n:name:testNotificationWorkspace": {
Expand Down Expand Up @@ -801,7 +860,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"s:name:testStateWorkspace": {
Expand Down Expand Up @@ -841,7 +904,11 @@ describe("Presence", () => {
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"n:name:testNotificationWorkspace": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,16 @@ describe("Presence", () => {
{
type: "Pres:DatastoreUpdate",
content: {
"sendTimestamp": 1020,
"sendTimestamp": clock.now,
"avgLatency": 10,
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"n:name:testNotificationWorkspace": {
Expand Down Expand Up @@ -190,12 +194,16 @@ describe("Presence", () => {
{
type: "Pres:DatastoreUpdate",
content: {
"sendTimestamp": 1020,
"sendTimestamp": clock.now,
"avgLatency": 10,
"data": {
"system:presence": {
"clientToSessionId": {
[connectionId2]: { "rev": 0, "timestamp": 1000, "value": attendeeId2 },
[connectionId2]: {
"rev": 0,
"timestamp": initialTime,
"value": attendeeId2,
},
},
},
"n:name:testNotificationWorkspace": {
Expand Down
Loading
Loading