33 * Licensed under the MIT License.
44 */
55
6+ import { strict as assert } from "node:assert" ;
7+
68import { EventAndErrorTrackingLogger } from "@fluidframework/test-utils/internal" ;
79import { describe , it , after , afterEach , before , beforeEach } from "mocha" ;
810import { useFakeTimers , type SinonFakeTimers } from "sinon" ;
@@ -23,7 +25,8 @@ describe("Presence", () => {
2325 describe ( "batching" , ( ) => {
2426 let runtime : MockEphemeralRuntime ;
2527 let logger : EventAndErrorTrackingLogger ;
26- const initialTime = 1000 ;
28+ const initialTime = 500 ;
29+ const testStartTime = 1010 ;
2730 let clock : SinonFakeTimers ;
2831 let presence : PresenceWithNotifications ;
2932
@@ -35,8 +38,6 @@ describe("Presence", () => {
3538 logger = new EventAndErrorTrackingLogger ( ) ;
3639 runtime = new MockEphemeralRuntime ( logger ) ;
3740
38- // Note that while the initialTime is set to 1000, the prepareConnectedPresence call advances
39- // it to 1010 so all tests start at that time.
4041 clock . setSystemTime ( initialTime ) ;
4142
4243 // Set up the presence connection.
@@ -47,6 +48,12 @@ describe("Presence", () => {
4748 clock ,
4849 logger ,
4950 ) . presence ;
51+
52+ // Note that while the initialTime was set to 500, the prepareConnectedPresence call advances
53+ // it. Set a consistent start time for all tests.
54+ const deltaToStart = testStartTime - clock . now ;
55+ assert ( deltaToStart >= 0 ) ;
56+ clock . tick ( deltaToStart ) ;
5057 } ) ;
5158
5259 afterEach ( ( ) => {
@@ -72,7 +79,11 @@ describe("Presence", () => {
7279 "data" : {
7380 "system:presence" : {
7481 "clientToSessionId" : {
75- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
82+ [ connectionId2 ] : {
83+ "rev" : 0 ,
84+ "timestamp" : initialTime ,
85+ "value" : attendeeId2 ,
86+ } ,
7687 } ,
7788 } ,
7889 "s:name:testStateWorkspace" : {
@@ -99,7 +110,11 @@ describe("Presence", () => {
99110 "data" : {
100111 "system:presence" : {
101112 "clientToSessionId" : {
102- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
113+ [ connectionId2 ] : {
114+ "rev" : 0 ,
115+ "timestamp" : initialTime ,
116+ "value" : attendeeId2 ,
117+ } ,
103118 } ,
104119 } ,
105120 "s:name:testStateWorkspace" : {
@@ -126,7 +141,11 @@ describe("Presence", () => {
126141 "data" : {
127142 "system:presence" : {
128143 "clientToSessionId" : {
129- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
144+ [ connectionId2 ] : {
145+ "rev" : 0 ,
146+ "timestamp" : initialTime ,
147+ "value" : attendeeId2 ,
148+ } ,
130149 } ,
131150 } ,
132151 "s:name:testStateWorkspace" : {
@@ -168,7 +187,7 @@ describe("Presence", () => {
168187 assertFinalExpectations ( runtime , logger ) ;
169188 } ) ;
170189
171- it ( "sets timer for default allowableUpdateLatency " , async ( ) => {
190+ it ( "sets timer for default allowableUpdateLatencyMs " , async ( ) => {
172191 runtime . signalsExpected . push ( [
173192 {
174193 type : "Pres:DatastoreUpdate" ,
@@ -180,7 +199,7 @@ describe("Presence", () => {
180199 "clientToSessionId" : {
181200 [ connectionId2 ] : {
182201 "rev" : 0 ,
183- "timestamp" : 1000 ,
202+ "timestamp" : initialTime ,
184203 "value" : attendeeId2 ,
185204 } ,
186205 } ,
@@ -215,7 +234,7 @@ describe("Presence", () => {
215234 clock . tick ( 100 ) ; // Time is now 1110
216235 } ) ;
217236
218- it ( "batches signals sent within default allowableUpdateLatency " , async ( ) => {
237+ it ( "batches signals sent within default allowableUpdateLatencyMs " , async ( ) => {
219238 runtime . signalsExpected . push (
220239 [
221240 {
@@ -226,7 +245,11 @@ describe("Presence", () => {
226245 "data" : {
227246 "system:presence" : {
228247 "clientToSessionId" : {
229- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
248+ [ connectionId2 ] : {
249+ "rev" : 0 ,
250+ "timestamp" : initialTime ,
251+ "value" : attendeeId2 ,
252+ } ,
230253 } ,
231254 } ,
232255 "s:name:testStateWorkspace" : {
@@ -253,7 +276,11 @@ describe("Presence", () => {
253276 "data" : {
254277 "system:presence" : {
255278 "clientToSessionId" : {
256- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
279+ [ connectionId2 ] : {
280+ "rev" : 0 ,
281+ "timestamp" : initialTime ,
282+ "value" : attendeeId2 ,
283+ } ,
257284 } ,
258285 } ,
259286 "s:name:testStateWorkspace" : {
@@ -315,7 +342,7 @@ describe("Presence", () => {
315342 clock . tick ( 30 ) ; // Time is now 1180
316343 } ) ;
317344
318- it ( "batches signals sent within a specified allowableUpdateLatency " , async ( ) => {
345+ it ( "batches signals sent within a specified allowableUpdateLatencyMs " , async ( ) => {
319346 runtime . signalsExpected . push (
320347 [
321348 {
@@ -326,7 +353,11 @@ describe("Presence", () => {
326353 "data" : {
327354 "system:presence" : {
328355 "clientToSessionId" : {
329- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
356+ [ connectionId2 ] : {
357+ "rev" : 0 ,
358+ "timestamp" : initialTime ,
359+ "value" : attendeeId2 ,
360+ } ,
330361 } ,
331362 } ,
332363 "s:name:testStateWorkspace" : {
@@ -353,7 +384,11 @@ describe("Presence", () => {
353384 "data" : {
354385 "system:presence" : {
355386 "clientToSessionId" : {
356- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
387+ [ connectionId2 ] : {
388+ "rev" : 0 ,
389+ "timestamp" : initialTime ,
390+ "value" : attendeeId2 ,
391+ } ,
357392 } ,
358393 } ,
359394 "s:name:testStateWorkspace" : {
@@ -424,7 +459,11 @@ describe("Presence", () => {
424459 "data" : {
425460 "system:presence" : {
426461 "clientToSessionId" : {
427- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
462+ [ connectionId2 ] : {
463+ "rev" : 0 ,
464+ "timestamp" : initialTime ,
465+ "value" : attendeeId2 ,
466+ } ,
428467 } ,
429468 } ,
430469 "s:name:testStateWorkspace" : {
@@ -460,7 +499,11 @@ describe("Presence", () => {
460499 "data" : {
461500 "system:presence" : {
462501 "clientToSessionId" : {
463- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
502+ [ connectionId2 ] : {
503+ "rev" : 0 ,
504+ "timestamp" : initialTime ,
505+ "value" : attendeeId2 ,
506+ } ,
464507 } ,
465508 } ,
466509 "s:name:testStateWorkspace" : {
@@ -530,7 +573,11 @@ describe("Presence", () => {
530573 "data" : {
531574 "system:presence" : {
532575 "clientToSessionId" : {
533- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
576+ [ connectionId2 ] : {
577+ "rev" : 0 ,
578+ "timestamp" : initialTime ,
579+ "value" : attendeeId2 ,
580+ } ,
534581 } ,
535582 } ,
536583 "s:name:testStateWorkspace" : {
@@ -566,7 +613,11 @@ describe("Presence", () => {
566613 "data" : {
567614 "system:presence" : {
568615 "clientToSessionId" : {
569- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
616+ [ connectionId2 ] : {
617+ "rev" : 0 ,
618+ "timestamp" : initialTime ,
619+ "value" : attendeeId2 ,
620+ } ,
570621 } ,
571622 } ,
572623 "s:name:testStateWorkspace" : {
@@ -632,7 +683,7 @@ describe("Presence", () => {
632683 "clientToSessionId" : {
633684 [ connectionId2 ] : {
634685 "rev" : 0 ,
635- "timestamp" : 1000 ,
686+ "timestamp" : initialTime ,
636687 "value" : attendeeId2 ,
637688 } ,
638689 } ,
@@ -713,7 +764,11 @@ describe("Presence", () => {
713764 "data" : {
714765 "system:presence" : {
715766 "clientToSessionId" : {
716- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
767+ [ connectionId2 ] : {
768+ "rev" : 0 ,
769+ "timestamp" : initialTime ,
770+ "value" : attendeeId2 ,
771+ } ,
717772 } ,
718773 } ,
719774 "n:name:testNotificationWorkspace" : {
@@ -739,7 +794,11 @@ describe("Presence", () => {
739794 "data" : {
740795 "system:presence" : {
741796 "clientToSessionId" : {
742- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
797+ [ connectionId2 ] : {
798+ "rev" : 0 ,
799+ "timestamp" : initialTime ,
800+ "value" : attendeeId2 ,
801+ } ,
743802 } ,
744803 } ,
745804 "n:name:testNotificationWorkspace" : {
@@ -801,7 +860,11 @@ describe("Presence", () => {
801860 "data" : {
802861 "system:presence" : {
803862 "clientToSessionId" : {
804- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
863+ [ connectionId2 ] : {
864+ "rev" : 0 ,
865+ "timestamp" : initialTime ,
866+ "value" : attendeeId2 ,
867+ } ,
805868 } ,
806869 } ,
807870 "s:name:testStateWorkspace" : {
@@ -841,7 +904,11 @@ describe("Presence", () => {
841904 "data" : {
842905 "system:presence" : {
843906 "clientToSessionId" : {
844- [ connectionId2 ] : { "rev" : 0 , "timestamp" : 1000 , "value" : attendeeId2 } ,
907+ [ connectionId2 ] : {
908+ "rev" : 0 ,
909+ "timestamp" : initialTime ,
910+ "value" : attendeeId2 ,
911+ } ,
845912 } ,
846913 } ,
847914 "n:name:testNotificationWorkspace" : {
0 commit comments