@@ -46,7 +46,7 @@ describe_only_db('mongo')('Parse.Query with comment testing', () => {
4646 } ) ;
4747
4848 it ( 'send comment with query through REST' , async ( ) => {
49- const comment = ' Hello Parse' ;
49+ const comment = ` Hello Parse ${ Date . now ( ) } ` ;
5050 const object = new TestObject ( ) ;
5151 object . set ( 'name' , 'object' ) ;
5252 await object . save ( ) ;
@@ -58,23 +58,55 @@ describe_only_db('mongo')('Parse.Query with comment testing', () => {
5858 } ,
5959 } ) ;
6060 await request ( options ) ;
61- const result = await database . collection ( 'system.profile' ) . findOne ( { } , { sort : { ts : - 1 } } ) ;
61+
62+ // Wait for profile entry to appear with retry logic
63+ let result ;
64+ const maxRetries = 10 ;
65+ const retryDelay = 100 ;
66+ for ( let i = 0 ; i < maxRetries ; i ++ ) {
67+ result = await database . collection ( 'system.profile' ) . findOne (
68+ { 'command.explain.comment' : comment } ,
69+ { sort : { ts : - 1 } }
70+ ) ;
71+ if ( result ) {
72+ break ;
73+ }
74+ await new Promise ( resolve => setTimeout ( resolve , retryDelay ) ) ;
75+ }
76+
77+ expect ( result ) . toBeDefined ( ) ;
6278 expect ( result . command . explain . comment ) . toBe ( comment ) ;
6379 } ) ;
6480
6581 it ( 'send comment with query' , async ( ) => {
66- const comment = ' Hello Parse' ;
82+ const comment = ` Hello Parse ${ Date . now ( ) } ` ;
6783 const object = new TestObject ( ) ;
6884 object . set ( 'name' , 'object' ) ;
6985 await object . save ( ) ;
7086 const collection = await config . database . adapter . _adaptiveCollection ( 'TestObject' ) ;
7187 await collection . _rawFind ( { name : 'object' } , { comment : comment } ) ;
72- const result = await database . collection ( 'system.profile' ) . findOne ( { } , { sort : { ts : - 1 } } ) ;
88+
89+ // Wait for profile entry to appear with retry logic
90+ let result ;
91+ const maxRetries = 10 ;
92+ const retryDelay = 100 ;
93+ for ( let i = 0 ; i < maxRetries ; i ++ ) {
94+ result = await database . collection ( 'system.profile' ) . findOne (
95+ { 'command.comment' : comment } ,
96+ { sort : { ts : - 1 } }
97+ ) ;
98+ if ( result ) {
99+ break ;
100+ }
101+ await new Promise ( resolve => setTimeout ( resolve , retryDelay ) ) ;
102+ }
103+
104+ expect ( result ) . toBeDefined ( ) ;
73105 expect ( result . command . comment ) . toBe ( comment ) ;
74106 } ) ;
75107
76108 it ( 'send a comment with a count query' , async ( ) => {
77- const comment = ' Hello Parse' ;
109+ const comment = ` Hello Parse ${ Date . now ( ) } ` ;
78110 const object = new TestObject ( ) ;
79111 object . set ( 'name' , 'object' ) ;
80112 await object . save ( ) ;
@@ -86,12 +118,28 @@ describe_only_db('mongo')('Parse.Query with comment testing', () => {
86118 const collection = await config . database . adapter . _adaptiveCollection ( 'TestObject' ) ;
87119 const countResult = await collection . count ( { name : 'object' } , { comment : comment } ) ;
88120 expect ( countResult ) . toEqual ( 2 ) ;
89- const result = await database . collection ( 'system.profile' ) . findOne ( { } , { sort : { ts : - 1 } } ) ;
121+
122+ // Wait for profile entry to appear with retry logic
123+ let result ;
124+ const maxRetries = 10 ;
125+ const retryDelay = 100 ;
126+ for ( let i = 0 ; i < maxRetries ; i ++ ) {
127+ result = await database . collection ( 'system.profile' ) . findOne (
128+ { 'command.comment' : comment } ,
129+ { sort : { ts : - 1 } }
130+ ) ;
131+ if ( result ) {
132+ break ;
133+ }
134+ await new Promise ( resolve => setTimeout ( resolve , retryDelay ) ) ;
135+ }
136+
137+ expect ( result ) . toBeDefined ( ) ;
90138 expect ( result . command . comment ) . toBe ( comment ) ;
91139 } ) ;
92140
93141 it ( 'attach a comment to an aggregation' , async ( ) => {
94- const comment = ' Hello Parse' ;
142+ const comment = ` Hello Parse ${ Date . now ( ) } ` ;
95143 const object = new TestObject ( ) ;
96144 object . set ( 'name' , 'object' ) ;
97145 await object . save ( ) ;
@@ -100,7 +148,23 @@ describe_only_db('mongo')('Parse.Query with comment testing', () => {
100148 explain : true ,
101149 comment : comment ,
102150 } ) ;
103- const result = await database . collection ( 'system.profile' ) . findOne ( { } , { sort : { ts : - 1 } } ) ;
151+
152+ // Wait for profile entry to appear with retry logic
153+ let result ;
154+ const maxRetries = 10 ;
155+ const retryDelay = 100 ;
156+ for ( let i = 0 ; i < maxRetries ; i ++ ) {
157+ result = await database . collection ( 'system.profile' ) . findOne (
158+ { 'command.explain.comment' : comment } ,
159+ { sort : { ts : - 1 } }
160+ ) ;
161+ if ( result ) {
162+ break ;
163+ }
164+ await new Promise ( resolve => setTimeout ( resolve , retryDelay ) ) ;
165+ }
166+
167+ expect ( result ) . toBeDefined ( ) ;
104168 expect ( result . command . explain . comment ) . toBe ( comment ) ;
105169 } ) ;
106170} ) ;
0 commit comments