@@ -221,7 +221,7 @@ public async Task StreamingChatCanBeCancelledAsync()
221221 Assert . That ( firstUpdate , Is . Not . Null ) ;
222222 Assert . That ( cancellationTokenSource . IsCancellationRequested , Is . False ) ;
223223
224- Thread . Sleep ( 1000 ) ;
224+ await Task . Delay ( 1000 ) ;
225225
226226 Assert . ThrowsAsync < OperationCanceledException > ( async ( ) =>
227227 {
@@ -1090,7 +1090,7 @@ public async Task GetChatCompletionsWithPagination()
10901090 completionIds . Add ( completion . Id ) ;
10911091 }
10921092
1093- Thread . Sleep ( 5000 ) ; // Wait for completions to be stored
1093+ await Task . Delay ( 5000 ) ; // Wait for completions to be stored
10941094
10951095 // Test pagination with limit
10961096 ChatCompletionCollectionOptions paginationOptions = new ( )
@@ -1146,7 +1146,7 @@ public async Task GetChatCompletionsWithAfterIdPagination()
11461146 completionIds . Add ( completion . Id ) ;
11471147 }
11481148
1149- Thread . Sleep ( 5000 ) ; // Wait for completions to be stored
1149+ await Task . Delay ( 5000 ) ; // Wait for completions to be stored
11501150
11511151 // Get first completion to use as afterId
11521152 string afterId = null ;
@@ -1205,10 +1205,10 @@ public async Task GetChatCompletionsWithOrderFiltering()
12051205 createOptions ) ;
12061206
12071207 completionIds . Add ( completion . Id ) ;
1208- Thread . Sleep ( 1000 ) ; // Ensure different timestamps
1208+ await Task . Delay ( 1000 ) ; // Ensure different timestamps
12091209 }
12101210
1211- Thread . Sleep ( 5000 ) ; // Wait for completions to be stored
1211+ await Task . Delay ( 5000 ) ; // Wait for completions to be stored
12121212
12131213 // Test ascending order
12141214 ChatCompletionCollectionOptions ascOptions = new ( )
@@ -1290,7 +1290,7 @@ public async Task GetChatCompletionsWithMetadataFiltering()
12901290 options2 ) ;
12911291 completionIds . Add ( otherCompletion . Id ) ;
12921292
1293- Thread . Sleep ( 5000 ) ; // Wait for completions to be stored
1293+ await Task . Delay ( 5000 ) ; // Wait for completions to be stored
12941294
12951295 // Filter by specific metadata
12961296 ChatCompletionCollectionOptions filterOptions = new ( )
@@ -1338,7 +1338,7 @@ public async Task GetChatCompletionsWithModelFiltering()
13381338 [ "Model filter test: Say 'Hello'" ] ,
13391339 createOptions ) ;
13401340
1341- Thread . Sleep ( 5000 ) ; // Wait for completion to be stored
1341+ await Task . Delay ( 5000 ) ; // Wait for completion to be stored
13421342
13431343 // Filter by the model used by the test client
13441344 ChatCompletionCollectionOptions filterOptions = new ( )
@@ -1381,7 +1381,7 @@ public async Task GetChatCompletionsWithEmptyOptions()
13811381 [ "Empty options test: Say 'Hello'" ] ,
13821382 createOptions ) ;
13831383
1384- Thread . Sleep ( 5000 ) ; // Wait for completion to be stored
1384+ await Task . Delay ( 5000 ) ; // Wait for completion to be stored
13851385
13861386 // Test with default/empty options
13871387 int count = 0 ;
@@ -1424,7 +1424,7 @@ public async Task GetChatCompletionsWithCombinedFilters()
14241424 [ "Combined filters test: Say 'Combined test'" ] ,
14251425 createOptions ) ;
14261426
1427- Thread . Sleep ( 5000 ) ; // Wait for completion to be stored
1427+ await Task . Delay ( 6000 ) ; // Wait for completion to be stored
14281428
14291429 // Test with combined filters
14301430 ChatCompletionCollectionOptions combinedOptions = new ( )
@@ -1522,18 +1522,20 @@ public async Task StoredChatCompletionsWork()
15221522 [ new UserChatMessage ( "Say `this is a test`." ) ] ,
15231523 options ) ;
15241524
1525- Thread . Sleep ( 5000 ) ;
1525+ await RetryWithExponentialBackoffAsync ( async ( ) =>
1526+ {
15261527
1527- ChatCompletion storedCompletion = await client . GetChatCompletionAsync ( completion . Id ) ;
1528+ ChatCompletion storedCompletion = await client . GetChatCompletionAsync ( completion . Id ) ;
15281529
1529- Assert . That ( storedCompletion . Id , Is . EqualTo ( completion . Id ) ) ;
1530- Assert . That ( storedCompletion . Content [ 0 ] . Text , Is . EqualTo ( completion . Content [ 0 ] . Text ) ) ;
1530+ Assert . That ( storedCompletion . Id , Is . EqualTo ( completion . Id ) ) ;
1531+ Assert . That ( storedCompletion . Content [ 0 ] . Text , Is . EqualTo ( completion . Content [ 0 ] . Text ) ) ;
15311532
1532- ChatCompletionDeletionResult deletionResult = await client . DeleteChatCompletionAsync ( completion . Id ) ;
1533+ ChatCompletionDeletionResult deletionResult = await client . DeleteChatCompletionAsync ( completion . Id ) ;
15331534
1534- Assert . That ( deletionResult . Deleted , Is . True ) ;
1535+ Assert . That ( deletionResult . Deleted , Is . True ) ;
1536+ } ) ;
15351537
1536- Thread . Sleep ( 5000 ) ;
1538+ await Task . Delay ( 5000 ) ;
15371539
15381540 Assert . ThrowsAsync < ClientResultException > ( async ( ) =>
15391541 {
@@ -1571,7 +1573,7 @@ public async Task GetChatCompletionsValidatesCollectionEnumeration()
15711573 [ "Enumeration test: Say 'Test enumeration'" ] ,
15721574 createOptions ) ;
15731575
1574- Thread . Sleep ( 5000 ) ; // Wait for completion to be stored
1576+ await Task . Delay ( 5000 ) ; // Wait for completion to be stored
15751577
15761578 // Test that we can enumerate multiple times
15771579 ChatCompletionCollectionOptions collectionOptions = new ( )
@@ -1625,7 +1627,7 @@ public async Task GetChatCompletionsHandlesLargeLimits()
16251627 [ "Large limit test: Say 'Testing large limits'" ] ,
16261628 createOptions ) ;
16271629
1628- Thread . Sleep ( 5000 ) ; // Wait for completion to be stored
1630+ await Task . Delay ( 5000 ) ; // Wait for completion to be stored
16291631
16301632 // Test with a large page size limit
16311633 ChatCompletionCollectionOptions largeOptions = new ( )
@@ -1666,7 +1668,7 @@ public async Task GetChatCompletionsWithMinimalLimits()
16661668 [ "Minimal limit test: Say 'Testing minimal limits'" ] ,
16671669 createOptions ) ;
16681670
1669- Thread . Sleep ( 5000 ) ; // Wait for completion to be stored
1671+ await Task . Delay ( 5000 ) ; // Wait for completion to be stored
16701672
16711673 // Test with minimal page size
16721674 ChatCompletionCollectionOptions minimalOptions = new ( )
@@ -1974,72 +1976,6 @@ await RetryWithExponentialBackoffAsync(async () =>
19741976 catch { /* Ignore cleanup errors */ }
19751977 }
19761978
1977- [ Test ]
1978- public async Task GetChatCompletionMessagesWithMessageProperties ( )
1979- {
1980- ChatClient client = GetTestClient ( ) ;
1981-
1982- // Create completion with function calling to test various message properties
1983- ChatTool calculatorTool = ChatTool . CreateFunctionTool (
1984- "calculate" ,
1985- "Perform basic calculations" ,
1986- BinaryData . FromString ( """
1987- {
1988- "type": "object",
1989- "properties": {
1990- "expression": {
1991- "type": "string",
1992- "description": "Mathematical expression to evaluate"
1993- }
1994- },
1995- "required": ["expression"]
1996- }
1997- """ ) ) ;
1998-
1999- ChatCompletionOptions createOptions = new ( )
2000- {
2001- StoredOutputEnabled = true ,
2002- Tools = { calculatorTool } ,
2003- Metadata = { [ "test_scenario" ] = "message_properties" }
2004- } ;
2005-
2006- ChatCompletion completion = await client . CompleteChatAsync (
2007- [ "Message properties test: Calculate 2 + 2" ] ,
2008- createOptions ) ;
2009-
2010- await RetryWithExponentialBackoffAsync ( async ( ) =>
2011- {
2012- // Test message properties
2013- bool foundUserMessage = false ;
2014- bool foundAssistantMessage = false ;
2015-
2016- await foreach ( var message in client . GetChatCompletionMessagesAsync ( completion . Id ) )
2017- {
2018- // Validate required properties
2019- Assert . That ( message . Id , Is . Not . Null . And . Not . Empty ) ;
2020-
2021- // Test collections are properly initialized
2022- Assert . That ( message . ToolCalls , Is . Not . Null ) ;
2023- Assert . That ( message . Annotations , Is . Not . Null ) ;
2024-
2025- // Refusal should be null or a string
2026- if ( message . Refusal != null )
2027- {
2028- Assert . That ( message . Refusal , Is . TypeOf < string > ( ) ) ;
2029- }
2030- }
2031-
2032- Assert . That ( foundUserMessage || foundAssistantMessage , Is . True , "Should find at least one message" ) ;
2033- } ) ;
2034-
2035- // Clean up
2036- try
2037- {
2038- await client . DeleteChatCompletionAsync ( completion . Id ) ;
2039- }
2040- catch { /* Ignore cleanup errors */ }
2041- }
2042-
20431979 [ Test ]
20441980 public async Task GetChatCompletionMessagesWithCombinedOptions ( )
20451981 {
0 commit comments