2
2
// Licensed under the MIT License. See License.txt in the project root for license information.
3
3
4
4
using System ;
5
- using System . Collections ;
6
5
using System . Collections . Generic ;
7
- using System . Collections . Immutable ;
8
6
using System . IO ;
9
7
using System . IO . Abstractions ;
10
8
using System . Linq ;
14
12
using System . Threading ;
15
13
using System . Threading . Tasks ;
16
14
using Microsoft . Azure . WebJobs . Host . Executors ;
17
- using Microsoft . Azure . WebJobs . Script . BindingExtensions ;
18
15
using Microsoft . Azure . WebJobs . Script . Config ;
19
- using Microsoft . Azure . WebJobs . Script . Models ;
20
16
using Microsoft . Azure . WebJobs . Script . WebHost ;
21
17
using Microsoft . Azure . WebJobs . Script . WebHost . Management ;
22
18
using Microsoft . Azure . WebJobs . Script . Workers . Rpc ;
27
23
using Moq ;
28
24
using Newtonsoft . Json ;
29
25
using Newtonsoft . Json . Linq ;
30
- using NuGet . Packaging . Signing ;
31
26
using Xunit ;
32
27
33
28
namespace Microsoft . Azure . WebJobs . Script . Tests . Managment
@@ -49,6 +44,7 @@ public class FunctionsSyncManagerTests : IDisposable
49
44
private readonly Mock < IEnvironment > _mockEnvironment ;
50
45
private readonly HostNameProvider _hostNameProvider ;
51
46
private string _function1 ;
47
+ private bool _emptyContent ;
52
48
53
49
public FunctionsSyncManagerTests ( )
54
50
{
@@ -285,14 +281,32 @@ private void VerifyResultWithCacheOff()
285
281
}
286
282
287
283
[ Fact ]
288
- public async Task TrySyncTriggers_CheckHash_PostsExpectedContent ( )
284
+ public async Task TrySyncTriggers_BackgroundSync_DoesNotPostsEmptyContent ( )
285
+ {
286
+ _emptyContent = true ;
287
+
288
+ using ( var env = new TestScopedEnvironmentVariable ( _vars ) )
289
+ {
290
+ var syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( isBackgroundSync : true ) ;
291
+ Assert . Equal ( 0 , _mockHttpHandler . RequestCount ) ;
292
+ Assert . Equal ( 0 , _contentBuilder . Length ) ;
293
+ Assert . True ( syncResult . Success ) ;
294
+ Assert . Null ( syncResult . Error ) ;
295
+
296
+ var logs = _loggerProvider . GetAllLogMessages ( ) . Select ( p => p . FormattedMessage ) . ToArray ( ) ;
297
+ Assert . Equal ( "No functions found. Skipping Sync operation." , logs . Single ( ) ) ;
298
+ }
299
+ }
300
+
301
+ [ Fact ]
302
+ public async Task TrySyncTriggers_BackgroundSync_PostsExpectedContent ( )
289
303
{
290
304
using ( var env = new TestScopedEnvironmentVariable ( _vars ) )
291
305
{
292
306
var hashBlob = await _functionsSyncManager . GetHashBlobAsync ( ) ;
293
307
await hashBlob . DeleteIfExistsAsync ( ) ;
294
308
295
- var syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( checkHash : true ) ;
309
+ var syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( isBackgroundSync : true ) ;
296
310
Assert . True ( syncResult . Success ) ;
297
311
Assert . Null ( syncResult . Error ) ;
298
312
Assert . Equal ( 1 , _mockHttpHandler . RequestCount ) ;
@@ -319,7 +333,7 @@ public async Task TrySyncTriggers_CheckHash_PostsExpectedContent()
319
333
_loggerProvider . ClearAllLogMessages ( ) ;
320
334
ResetMockFileSystem ( ) ;
321
335
_mockHttpHandler . Reset ( ) ;
322
- syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( checkHash : true ) ;
336
+ syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( isBackgroundSync : true ) ;
323
337
Assert . Equal ( 0 , _mockHttpHandler . RequestCount ) ;
324
338
Assert . Equal ( 0 , _contentBuilder . Length ) ;
325
339
Assert . True ( syncResult . Success ) ;
@@ -332,23 +346,23 @@ public async Task TrySyncTriggers_CheckHash_PostsExpectedContent()
332
346
// simulate a function change resulting in a new hash value
333
347
ResetMockFileSystem ( "{}" ) ;
334
348
_mockHttpHandler . Reset ( ) ;
335
- syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( checkHash : true ) ;
349
+ syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( isBackgroundSync : true ) ;
336
350
Assert . Equal ( 1 , _mockHttpHandler . RequestCount ) ;
337
351
Assert . True ( syncResult . Success ) ;
338
352
Assert . Null ( syncResult . Error ) ;
339
353
}
340
354
}
341
355
342
356
[ Fact ]
343
- public async Task TrySyncTriggers_CheckHash_SetTriggersFailure_HashNotUpdated ( )
357
+ public async Task TrySyncTriggers_BackgroundSync_SetTriggersFailure_HashNotUpdated ( )
344
358
{
345
359
using ( var env = new TestScopedEnvironmentVariable ( _vars ) )
346
360
{
347
361
var hashBlob = await _functionsSyncManager . GetHashBlobAsync ( ) ;
348
362
await hashBlob . DeleteIfExistsAsync ( ) ;
349
363
350
364
_mockHttpHandler . MockStatusCode = HttpStatusCode . InternalServerError ;
351
- var syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( checkHash : true ) ;
365
+ var syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( isBackgroundSync : true ) ;
352
366
Assert . False ( syncResult . Success ) ;
353
367
string expectedErrorMessage = "SyncTriggers call failed (StatusCode=InternalServerError)." ;
354
368
Assert . Equal ( expectedErrorMessage , syncResult . Error ) ;
@@ -675,12 +689,22 @@ private IFileSystem CreateFileSystem(ScriptApplicationHostOptions hostOptions, s
675
689
dirBase . Setup ( d => d . Exists ( rootPath ) ) . Returns ( true ) ;
676
690
dirBase . Setup ( d => d . Exists ( Path . Combine ( rootPath , "bin" ) ) ) . Returns ( true ) ;
677
691
dirBase . Setup ( d => d . EnumerateDirectories ( rootPath ) )
678
- . Returns ( new [ ]
692
+ . Returns ( ( ) =>
679
693
{
680
- Path . Combine ( rootPath , "bin" ) ,
681
- Path . Combine ( rootPath , "function1" ) ,
682
- Path . Combine ( rootPath , "function2" ) ,
683
- Path . Combine ( rootPath , "function3" )
694
+ if ( _emptyContent )
695
+ {
696
+ return new string [ 0 ] ;
697
+ }
698
+ else
699
+ {
700
+ return new [ ]
701
+ {
702
+ Path . Combine ( rootPath , "bin" ) ,
703
+ Path . Combine ( rootPath , "function1" ) ,
704
+ Path . Combine ( rootPath , "function2" ) ,
705
+ Path . Combine ( rootPath , "function3" )
706
+ } ;
707
+ }
684
708
} ) ;
685
709
686
710
_function1 = @"{
0 commit comments