@@ -75,14 +75,30 @@ await this.WaitForProductChanges(
7575 [ Fact ]
7676 public async Task BatchSizeOverrideTriggerTest ( )
7777 {
78- const int batchSize = 20 ;
78+ // Use enough items to require 4 batches to be processed but then
79+ // set the batch size to the same value so they can all be processed in one
80+ // batch. The test will only wait for ~1 batch worth of time so will timeout
81+ // if the batch size isn't actually changed
82+ const int batchSize = SqlTableChangeMonitor < object > . DefaultBatchSize * 4 ;
7983 const int firstId = 1 ;
80- const int lastId = 40 ;
84+ const int lastId = batchSize ;
8185 this . EnableChangeTrackingForTable ( "Products" ) ;
82- this . StartFunctionHost ( nameof ( ProductsTriggerWithValidation ) , SupportedLanguages . CSharp , true , environmentVariables : new Dictionary < string , string > ( ) {
83- { "TEST_EXPECTED_BATCH_SIZE" , batchSize . ToString ( ) } ,
84- { "Sql_Trigger_BatchSize" , batchSize . ToString ( ) }
85- } ) ;
86+ var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
87+ DataReceivedEventHandler handler = TestUtils . CreateOutputReceievedHandler (
88+ taskCompletionSource ,
89+ @"Starting change consumption loop. BatchSize: (\d*) PollingIntervalMs: \d*" ,
90+ "BatchSize" ,
91+ batchSize . ToString ( ) ) ;
92+ this . StartFunctionHost (
93+ nameof ( ProductsTriggerWithValidation ) ,
94+ SupportedLanguages . CSharp ,
95+ useTestFolder : true ,
96+ customOutputHandler : handler ,
97+ environmentVariables : new Dictionary < string , string > ( ) {
98+ { "TEST_EXPECTED_BATCH_SIZE" , batchSize . ToString ( ) } ,
99+ { "Sql_Trigger_BatchSize" , batchSize . ToString ( ) }
100+ }
101+ ) ;
86102
87103 await this . WaitForProductChanges (
88104 firstId ,
@@ -92,6 +108,7 @@ await this.WaitForProductChanges(
92108 id => $ "Product { id } ",
93109 id => id * 100 ,
94110 this . GetBatchProcessingTimeout ( firstId , lastId , batchSize : batchSize ) ) ;
111+ await taskCompletionSource . Task . TimeoutAfter ( TimeSpan . FromSeconds ( 5000 ) , "Timed out waiting for BatchSize configuration message" ) ;
95112 }
96113
97114 /// <summary>
@@ -100,13 +117,28 @@ await this.WaitForProductChanges(
100117 [ Fact ]
101118 public async Task PollingIntervalOverrideTriggerTest ( )
102119 {
103- const int pollingIntervalMs = 100 ;
104120 const int firstId = 1 ;
105- const int lastId = 50 ;
121+ // Use enough items to require 5 batches to be processed - the test will
122+ // only wait for the expected time and timeout if the default polling
123+ // interval isn't actually modified.
124+ const int lastId = SqlTableChangeMonitor < object > . DefaultBatchSize * 5 ;
125+ const int pollingIntervalMs = SqlTableChangeMonitor < object > . DefaultPollingIntervalMs / 2 ;
106126 this . EnableChangeTrackingForTable ( "Products" ) ;
107- this . StartFunctionHost ( nameof ( ProductsTriggerWithValidation ) , SupportedLanguages . CSharp , true , environmentVariables : new Dictionary < string , string > ( ) {
108- { "Sql_Trigger_PollingIntervalMs" , pollingIntervalMs . ToString ( ) }
109- } ) ;
127+ var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
128+ DataReceivedEventHandler handler = TestUtils . CreateOutputReceievedHandler (
129+ taskCompletionSource ,
130+ @"Starting change consumption loop. BatchSize: \d* PollingIntervalMs: (\d*)" ,
131+ "PollingInterval" ,
132+ pollingIntervalMs . ToString ( ) ) ;
133+ this . StartFunctionHost (
134+ nameof ( ProductsTriggerWithValidation ) ,
135+ SupportedLanguages . CSharp ,
136+ useTestFolder : true ,
137+ customOutputHandler : handler ,
138+ environmentVariables : new Dictionary < string , string > ( ) {
139+ { "Sql_Trigger_PollingIntervalMs" , pollingIntervalMs . ToString ( ) }
140+ }
141+ ) ;
110142
111143 await this . WaitForProductChanges (
112144 firstId ,
@@ -116,9 +148,9 @@ await this.WaitForProductChanges(
116148 id => $ "Product { id } ",
117149 id => id * 100 ,
118150 this . GetBatchProcessingTimeout ( firstId , lastId , pollingIntervalMs : pollingIntervalMs ) ) ;
151+ await taskCompletionSource . Task . TimeoutAfter ( TimeSpan . FromSeconds ( 5000 ) , "Timed out waiting for PollingInterval configuration message" ) ;
119152 }
120153
121-
122154 /// <summary>
123155 /// Verifies that if several changes have happened to the table row since last invocation, then a single net
124156 /// change for that row is passed to the user function.
0 commit comments