@@ -30,3 +30,57 @@ test('PageViewEvent does not throw on Harvester driven processes', () => {
3030 sendEmptyBody : true
3131 } ) ) . toEqual ( true ) // mimics the manual trigger in PVE `sendRum`; this should return true as it actually tries to "send"
3232} )
33+
34+ test ( 'PageViewEvent reports SM on invalid timestamp' , ( ) => {
35+ const spy = jest . spyOn ( pveAggregate , 'reportSupportabilityMetric' )
36+ jest . useFakeTimers ( )
37+
38+ mainAgent . runtime . timeKeeper . processRumRequest ( undefined , 0 , 2 , Date . now ( ) + 20000 )
39+ expect ( mainAgent . runtime . timeKeeper . ready ) . toEqual ( true )
40+
41+ const originTime = mainAgent . runtime . timeKeeper . correctedOriginTime
42+ pveAggregate . postHarvestCleanup ( {
43+ status : 200 ,
44+ responseText : JSON . stringify ( {
45+ app : {
46+ agents : [ { entityGuid : 'Mjk0MjgxMXxCUk9XU0VSfEFQUExJQ0FUSU9OfDQwNzUwNDQ3NQ' } ] ,
47+ // agent's timestamp is in the future, so it is invalid
48+ nrServerTime : originTime - 10000
49+ }
50+ } ) ,
51+ xhr : { status : 200 } ,
52+ targetApp : undefined
53+ } )
54+
55+ expect ( spy ) . toHaveBeenCalledWith ( 'Generic/TimeKeeper/InvalidTimestamp/Seen' , 10000 )
56+
57+ jest . useRealTimers ( )
58+ spy . mockRestore ( )
59+ } )
60+
61+ test ( 'PageViewEvent does not report SM on valid timestamp' , ( ) => {
62+ const spy = jest . spyOn ( pveAggregate , 'reportSupportabilityMetric' )
63+ jest . useFakeTimers ( )
64+
65+ mainAgent . runtime . timeKeeper . processRumRequest ( undefined , 0 , 2 , Date . now ( ) + 20000 )
66+ expect ( mainAgent . runtime . timeKeeper . ready ) . toEqual ( true )
67+
68+ const originTime = mainAgent . runtime . timeKeeper . correctedOriginTime
69+ pveAggregate . postHarvestCleanup ( {
70+ status : 200 ,
71+ responseText : JSON . stringify ( {
72+ app : {
73+ agents : [ { entityGuid : 'Mjk0MjgxMXxCUk9XU0VSfEFQUExJQ0FUSU9OfDQwNzUwNDQ3NQ' } ] ,
74+ // agent's timestamp is in the past, so it is valid
75+ nrServerTime : originTime + 10000
76+ }
77+ } ) ,
78+ xhr : { status : 200 } ,
79+ targetApp : undefined
80+ } )
81+
82+ expect ( spy ) . not . toHaveBeenCalled ( )
83+
84+ jest . useRealTimers ( )
85+ spy . mockRestore ( )
86+ } )
0 commit comments