@@ -67,10 +67,18 @@ public async Task Auto_Instrument_With_StartupHook_Should_Capture_Transaction(st
6767			apmServer . RunInBackground ( port ) ; 
6868			var  waitHandle  =  new  ManualResetEvent ( false ) ; 
6969
70+ 			var  error  =  string . Empty ; 
71+ 
7072			apmServer . OnReceive  +=  o => 
7173			{ 
7274				if  ( o  is  TransactionDto ) 
7375					waitHandle . Set ( ) ; 
76+ 
77+ 				else  if  ( o  is  string  s )  // may occur if there is an error 
78+ 				{ 
79+ 					waitHandle . Set ( ) ; 
80+ 					error  =  s ; 
81+ 				} 
7482			} ; 
7583
7684			using  ( var  sampleApp  =  new  SampleApplication ( ) ) 
@@ -86,8 +94,9 @@ public async Task Auto_Instrument_With_StartupHook_Should_Capture_Transaction(st
8694				var  response  =  await  client . GetAsync ( uri ) ; 
8795
8896				response . IsSuccessStatusCode . Should ( ) . BeTrue ( ) ; 
97+ 				waitHandle . WaitOne ( TimeSpan . FromMinutes ( 1 ) ) ; 
8998
90- 				waitHandle . WaitOne ( TimeSpan . FromMinutes ( 2 ) ) ; 
99+ 				error . Should ( ) . BeEmpty ( ) ; 
91100				apmServer . ReceivedData . Transactions . Should ( ) . HaveCount ( 1 ) ; 
92101
93102				var  transaction  =  apmServer . ReceivedData . Transactions . First ( ) ; 
@@ -108,12 +117,22 @@ public async Task Auto_Instrument_With_StartupHook_Should_Capture_Error(string t
108117			var  transactionWaitHandle  =  new  ManualResetEvent ( false ) ; 
109118			var  errorWaitHandle  =  new  ManualResetEvent ( false ) ; 
110119
120+ 			var  serverError  =  string . Empty ; 
121+ 
111122			apmServer . OnReceive  +=  o => 
112123			{ 
113124				if  ( o  is  TransactionDto ) 
114125					transactionWaitHandle . Set ( ) ; 
115- 				if  ( o  is  ErrorDto ) 
126+ 
127+ 				else  if  ( o  is  ErrorDto ) 
116128					errorWaitHandle . Set ( ) ; 
129+ 
130+ 				else  if  ( o  is  string  s )  // may occur if there is an error 
131+ 				{ 
132+ 					transactionWaitHandle . Set ( ) ; 
133+ 					errorWaitHandle . Set ( ) ; 
134+ 					serverError  =  s ; 
135+ 				} 
117136			} ; 
118137
119138			using  ( var  sampleApp  =  new  SampleApplication ( ) ) 
@@ -131,13 +150,15 @@ public async Task Auto_Instrument_With_StartupHook_Should_Capture_Error(string t
131150
132151				response . IsSuccessStatusCode . Should ( ) . BeFalse ( ) ; 
133152
134- 				transactionWaitHandle . WaitOne ( TimeSpan . FromMinutes ( 2 ) ) ; 
153+ 				transactionWaitHandle . WaitOne ( TimeSpan . FromMinutes ( 1 ) ) ; 
154+ 				serverError . Should ( ) . BeEmpty ( ) ; 
135155				apmServer . ReceivedData . Transactions . Should ( ) . HaveCount ( 1 ) ; 
136156
137157				var  transaction  =  apmServer . ReceivedData . Transactions . First ( ) ; 
138158				transaction . Name . Should ( ) . Be ( "GET Home/Exception" ) ; 
139159
140- 				errorWaitHandle . WaitOne ( TimeSpan . FromMinutes ( 2 ) ) ; 
160+ 				errorWaitHandle . WaitOne ( TimeSpan . FromMinutes ( 1 ) ) ; 
161+ 				serverError . Should ( ) . BeEmpty ( ) ; 
141162				apmServer . ReceivedData . Errors . Should ( ) . HaveCount ( 1 ) ; 
142163
143164				var  error  =  apmServer . ReceivedData . Errors . First ( ) ; 
@@ -159,11 +180,19 @@ public async Task Auto_Instrument_With_StartupHook_Should_Capture_Metadata(
159180			var  port  =  apmServer . FindAvailablePortToListen ( ) ; 
160181			apmServer . RunInBackground ( port ) ; 
161182
183+ 			var  error  =  string . Empty ; 
162184			var  waitHandle  =  new  ManualResetEvent ( false ) ; 
185+ 
163186			apmServer . OnReceive  +=  o => 
164187			{ 
165188				if  ( o  is  MetadataDto ) 
166189					waitHandle . Set ( ) ; 
190+ 
191+ 				else  if  ( o  is  string  s )  // may occur if there is an error 
192+ 				{ 
193+ 					waitHandle . Set ( ) ; 
194+ 					error  =  s ; 
195+ 				} 
167196			} ; 
168197
169198			using  ( var  sampleApp  =  new  SampleApplication ( ) ) 
@@ -180,7 +209,9 @@ public async Task Auto_Instrument_With_StartupHook_Should_Capture_Metadata(
180209
181210				response . IsSuccessStatusCode . Should ( ) . BeTrue ( ) ; 
182211
183- 				waitHandle . WaitOne ( TimeSpan . FromMinutes ( 2 ) ) ; 
212+ 				waitHandle . WaitOne ( TimeSpan . FromMinutes ( 1 ) ) ; 
213+ 
214+ 				error . Should ( ) . BeEmpty ( ) ; 
184215				apmServer . ReceivedData . Metadata . Should ( ) . HaveCountGreaterOrEqualTo ( 1 ) ; 
185216
186217				var  metadata  =  apmServer . ReceivedData . Metadata . First ( ) ; 
0 commit comments