@@ -13,6 +13,10 @@ namespace System.Diagnostics.Metrics.Tests
13
13
{
14
14
public class MetricsTests
15
15
{
16
+ // We increase the timeout for remote execution to allow for longer-running tests.
17
+ // Ensure RemoteExecutor.IsSupported, otherwise the execution can throw PlatformNotSupportedException.
18
+ private static readonly RemoteInvokeOptions ? s_remoteExecutionOptions = RemoteExecutor . IsSupported ? new RemoteInvokeOptions { TimeOut = 600_000 } : null ;
19
+
16
20
[ Fact ]
17
21
public void MeasurementConstructionTest ( )
18
22
{
@@ -53,7 +57,7 @@ public void MeterConstructionTest()
53
57
Assert . Equal ( "v1.0" , meter . Version ) ;
54
58
55
59
Assert . Throws < ArgumentNullException > ( ( ) => new Meter ( name : null ) ) ;
56
- } ) . Dispose ( ) ;
60
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
57
61
}
58
62
59
63
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -82,7 +86,7 @@ public void InstrumentCreationTest()
82
86
83
87
ObservableGauge < double > observableGauge = meter . CreateObservableGauge < double > ( "ObservableGauge" , ( ) => 10 , "Fahrenheit" , "Fahrenheit ObservableGauge" ) ;
84
88
ValidateInstrumentInfo ( observableGauge , "ObservableGauge" , "Fahrenheit" , "Fahrenheit ObservableGauge" , false , true ) ;
85
- } ) . Dispose ( ) ;
89
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
86
90
}
87
91
88
92
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -99,7 +103,7 @@ public void CreateInstrumentParametersTest()
99
103
Assert . Throws < ArgumentNullException > ( ( ) => meter . CreateObservableUpDownCounter < Decimal > ( null , ( ) => 0 , "items" , "Items ObservableUpDownCounter" ) ) ;
100
104
Assert . Throws < ArgumentNullException > ( ( ) => meter . CreateObservableGauge < double > ( null , ( ) => 0 , "seconds" , "Seconds ObservableGauge" ) ) ;
101
105
102
- } ) . Dispose ( ) ;
106
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
103
107
}
104
108
105
109
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -169,7 +173,7 @@ public void SupportedGenericParameterTypesTest()
169
173
Assert . Throws < InvalidOperationException > ( ( ) => meter . CreateHistogram < ulong > ( "histogram1" , "seconds" , "Seconds histogram" ) ) ;
170
174
Assert . Throws < InvalidOperationException > ( ( ) => meter . CreateObservableCounter < sbyte > ( "observableCounter3" , ( ) => 0 , "seconds" , "Seconds ObservableCounter" ) ) ;
171
175
Assert . Throws < InvalidOperationException > ( ( ) => meter . CreateObservableGauge < ushort > ( "observableGauge7" , ( ) => 0 , "seconds" , "Seconds ObservableGauge" ) ) ;
172
- } ) . Dispose ( ) ;
176
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
173
177
}
174
178
175
179
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -228,7 +232,7 @@ public void ListeningToInstrumentsPublishingTest()
228
232
// MeasurementsCompleted should be called 4 times for every instrument.
229
233
Assert . Equal ( 0 , instrumentsEncountered ) ;
230
234
}
231
- } ) . Dispose ( ) ;
235
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
232
236
}
233
237
234
238
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -280,7 +284,7 @@ public void ThrowingExceptionsFromObservableInstrumentCallbacks()
280
284
Assert . Equal ( 11 , accumulated ) ;
281
285
}
282
286
283
- } ) . Dispose ( ) ;
287
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
284
288
}
285
289
286
290
[ ConditionalTheory ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -376,7 +380,7 @@ public void InstrumentMeasurementTest(bool useSpan)
376
380
Histogram < decimal > histogram6 = meter . CreateHistogram < decimal > ( "decimalHistogram" ) ;
377
381
InstrumentMeasurementAggregationValidation ( histogram6 , ( value , tags ) => { Record ( histogram6 , value , tags , useSpan ) ; } ) ;
378
382
379
- } , useSpan . ToString ( ) ) . Dispose ( ) ;
383
+ } , useSpan . ToString ( ) , s_remoteExecutionOptions ) . Dispose ( ) ;
380
384
381
385
void AddToCounter < T > ( Counter < T > counter , T delta , KeyValuePair < string , object ? > [ ] tags , bool useSpan ) where T : struct
382
386
{
@@ -723,7 +727,7 @@ public void ObservableInstrumentMeasurementTest()
723
727
ObservableGauge < decimal > observableGauge20 = meter . CreateObservableGauge < decimal > ( "decimalObservableGauge" , ( ) => decimalGaugeMeasurementList ) ;
724
728
ObservableInstrumentMeasurementAggregationValidation ( observableGauge20 , decimalGaugeMeasurementList ) ;
725
729
726
- } ) . Dispose ( ) ;
730
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
727
731
}
728
732
729
733
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -875,7 +879,7 @@ public void PassingVariableTagsParametersTest()
875
879
PublishHistogramMeasurement ( instrument as Histogram < decimal > , value , tags ) ;
876
880
return ( decimal ) ( value * 2 ) ;
877
881
} ) ;
878
- } ) . Dispose ( ) ;
882
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
879
883
}
880
884
881
885
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -963,7 +967,7 @@ public void MeterDisposalsTest()
963
967
listener . RecordObservableInstruments ( ) ;
964
968
Assert . Equal ( 13 , count ) ;
965
969
966
- } ) . Dispose ( ) ;
970
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
967
971
}
968
972
969
973
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1034,7 +1038,7 @@ public void ListenerDisposalsTest()
1034
1038
1035
1039
listener . RecordObservableInstruments ( ) ;
1036
1040
Assert . Equal ( 7 , count ) ;
1037
- } ) . Dispose ( ) ;
1041
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1038
1042
}
1039
1043
1040
1044
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1102,7 +1106,7 @@ public void ListenerWithoutMeasurementsCompletedDisposalsTest()
1102
1106
1103
1107
listener . RecordObservableInstruments ( ) ;
1104
1108
Assert . Equal ( 7 , count ) ;
1105
- } ) . Dispose ( ) ;
1109
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1106
1110
}
1107
1111
1108
1112
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1147,7 +1151,7 @@ public void MultipleListenersTest()
1147
1151
1148
1152
gauge . Record ( 1 ) ;
1149
1153
Assert . Equal ( 15 , count ) ;
1150
- } ) . Dispose ( ) ;
1154
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1151
1155
}
1152
1156
1153
1157
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1184,7 +1188,7 @@ public void NullMeasurementEventCallbackTest()
1184
1188
Assert . Equal ( 2 , count ) ;
1185
1189
1186
1190
Assert . Throws < InvalidOperationException > ( ( ) => listener . SetMeasurementEventCallback < ulong > ( null ) ) ;
1187
- } ) . Dispose ( ) ;
1191
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1188
1192
}
1189
1193
1190
1194
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1225,7 +1229,7 @@ public void EnableListeningMultipleTimesWithDifferentState()
1225
1229
1226
1230
listener . Dispose ( ) ;
1227
1231
Assert . Equal ( 4 , completedCount ) ;
1228
- } ) . Dispose ( ) ;
1232
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1229
1233
}
1230
1234
1231
1235
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1268,7 +1272,7 @@ public void ParallelRunningTest()
1268
1272
Task . WaitAll ( taskList ) ;
1269
1273
1270
1274
Assert . Equal ( loopLength * 17 , totalCount ) ;
1271
- } ) . Dispose ( ) ;
1275
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1272
1276
}
1273
1277
1274
1278
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1337,7 +1341,7 @@ public void SerializedEventsTest()
1337
1341
Task . WaitAll ( jobs ) ;
1338
1342
listener . Dispose ( ) ;
1339
1343
Assert . Equal ( 0 , instruments . Count ) ;
1340
- } ) . Dispose ( ) ;
1344
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1341
1345
}
1342
1346
1343
1347
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1441,7 +1445,7 @@ public void TestRecordingMeasurementsWithTagList()
1441
1445
expectedTags [ 8 ] , expectedTags [ 9 ] , expectedTags [ 10 ] , expectedTags [ 11 ] , expectedTags [ 12 ] } ) ;
1442
1446
}
1443
1447
1444
- } ) . Dispose ( ) ;
1448
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1445
1449
}
1446
1450
1447
1451
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1529,7 +1533,7 @@ public void TestMeterCreationWithOptions()
1529
1533
Assert . Equal ( "10.0" , meter10 . Version ) ;
1530
1534
Assert . Equal ( "Scope10" , meter10 . Scope ) ;
1531
1535
Assert . Equal ( "TestMeterCreationWithOptions10" , meter10 . Name ) ;
1532
- } ) . Dispose ( ) ;
1536
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1533
1537
}
1534
1538
1535
1539
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1662,7 +1666,7 @@ public void TestCachedInstruments()
1662
1666
1663
1667
Gauge < int > gauge12 = meter . CreateGauge < int > ( "name9" , null , null , t1 ) ;
1664
1668
Assert . NotSame ( gauge9 , gauge12 ) ;
1665
- } ) . Dispose ( ) ;
1669
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1666
1670
}
1667
1671
1668
1672
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1728,7 +1732,7 @@ public void TestInstrumentCreationWithTags()
1728
1732
{
1729
1733
Assert . True ( string . Compare ( insArray [ i ] . Key , insArray [ i + 1 ] . Key , StringComparison . Ordinal ) <= 0 ) ;
1730
1734
}
1731
- } ) . Dispose ( ) ;
1735
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1732
1736
}
1733
1737
1734
1738
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1748,7 +1752,7 @@ public void TestHistogramCreationWithAdvice()
1748
1752
1749
1753
Assert . NotNull ( histogramWithAdvice . Advice ? . HistogramBucketBoundaries ) ;
1750
1754
Assert . Equal ( explicitBucketBoundaries , histogramWithAdvice . Advice . HistogramBucketBoundaries ) ;
1751
- } ) . Dispose ( ) ;
1755
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1752
1756
}
1753
1757
1754
1758
[ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
@@ -1771,7 +1775,7 @@ public void TestRecordingWithEmptyTagList()
1771
1775
counter . Add ( 1 , new TagList ( Array . Empty < KeyValuePair < string , object > > ( ) ) ) ;
1772
1776
1773
1777
Assert . Equal ( 4 , count ) ;
1774
- } ) . Dispose ( ) ;
1778
+ } , s_remoteExecutionOptions ) . Dispose ( ) ;
1775
1779
}
1776
1780
1777
1781
private void PublishCounterMeasurement < T > ( Counter < T > counter , T value , KeyValuePair < string , object ? > [ ] tags ) where T : struct
0 commit comments