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
6
using System . IO ;
8
7
using System . IO . Abstractions ;
13
12
using System . Threading ;
14
13
using System . Threading . Tasks ;
15
14
using Microsoft . Azure . WebJobs . Host . Executors ;
16
- using Microsoft . Azure . WebJobs . Script . BindingExtensions ;
17
15
using Microsoft . Azure . WebJobs . Script . Config ;
18
- using Microsoft . Azure . WebJobs . Script . Models ;
19
16
using Microsoft . Azure . WebJobs . Script . WebHost ;
20
17
using Microsoft . Azure . WebJobs . Script . WebHost . Management ;
21
18
using Microsoft . Azure . WebJobs . Script . Workers . Rpc ;
26
23
using Moq ;
27
24
using Newtonsoft . Json ;
28
25
using Newtonsoft . Json . Linq ;
29
- using NuGet . Packaging . Signing ;
30
26
using Xunit ;
31
27
32
28
namespace Microsoft . Azure . WebJobs . Script . Tests . Managment
@@ -48,6 +44,7 @@ public class FunctionsSyncManagerTests : IDisposable
48
44
private readonly Mock < IEnvironment > _mockEnvironment ;
49
45
private readonly HostNameProvider _hostNameProvider ;
50
46
private string _function1 ;
47
+ private bool _emptyContent ;
51
48
52
49
public FunctionsSyncManagerTests ( )
53
50
{
@@ -284,14 +281,32 @@ private void VerifyResultWithCacheOff()
284
281
}
285
282
286
283
[ Fact ]
287
- 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 ( )
288
303
{
289
304
using ( var env = new TestScopedEnvironmentVariable ( _vars ) )
290
305
{
291
306
var hashBlob = await _functionsSyncManager . GetHashBlobAsync ( ) ;
292
307
await hashBlob . DeleteIfExistsAsync ( ) ;
293
308
294
- var syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( checkHash : true ) ;
309
+ var syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( isBackgroundSync : true ) ;
295
310
Assert . True ( syncResult . Success ) ;
296
311
Assert . Null ( syncResult . Error ) ;
297
312
Assert . Equal ( 1 , _mockHttpHandler . RequestCount ) ;
@@ -318,7 +333,7 @@ public async Task TrySyncTriggers_CheckHash_PostsExpectedContent()
318
333
_loggerProvider . ClearAllLogMessages ( ) ;
319
334
ResetMockFileSystem ( ) ;
320
335
_mockHttpHandler . Reset ( ) ;
321
- syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( checkHash : true ) ;
336
+ syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( isBackgroundSync : true ) ;
322
337
Assert . Equal ( 0 , _mockHttpHandler . RequestCount ) ;
323
338
Assert . Equal ( 0 , _contentBuilder . Length ) ;
324
339
Assert . True ( syncResult . Success ) ;
@@ -331,23 +346,23 @@ public async Task TrySyncTriggers_CheckHash_PostsExpectedContent()
331
346
// simulate a function change resulting in a new hash value
332
347
ResetMockFileSystem ( "{}" ) ;
333
348
_mockHttpHandler . Reset ( ) ;
334
- syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( checkHash : true ) ;
349
+ syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( isBackgroundSync : true ) ;
335
350
Assert . Equal ( 1 , _mockHttpHandler . RequestCount ) ;
336
351
Assert . True ( syncResult . Success ) ;
337
352
Assert . Null ( syncResult . Error ) ;
338
353
}
339
354
}
340
355
341
356
[ Fact ]
342
- public async Task TrySyncTriggers_CheckHash_SetTriggersFailure_HashNotUpdated ( )
357
+ public async Task TrySyncTriggers_BackgroundSync_SetTriggersFailure_HashNotUpdated ( )
343
358
{
344
359
using ( var env = new TestScopedEnvironmentVariable ( _vars ) )
345
360
{
346
361
var hashBlob = await _functionsSyncManager . GetHashBlobAsync ( ) ;
347
362
await hashBlob . DeleteIfExistsAsync ( ) ;
348
363
349
364
_mockHttpHandler . MockStatusCode = HttpStatusCode . InternalServerError ;
350
- var syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( checkHash : true ) ;
365
+ var syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( isBackgroundSync : true ) ;
351
366
Assert . False ( syncResult . Success ) ;
352
367
string expectedErrorMessage = "SyncTriggers call failed (StatusCode=InternalServerError)." ;
353
368
Assert . Equal ( expectedErrorMessage , syncResult . Error ) ;
@@ -674,12 +689,22 @@ private IFileSystem CreateFileSystem(ScriptApplicationHostOptions hostOptions, s
674
689
dirBase . Setup ( d => d . Exists ( rootPath ) ) . Returns ( true ) ;
675
690
dirBase . Setup ( d => d . Exists ( Path . Combine ( rootPath , "bin" ) ) ) . Returns ( true ) ;
676
691
dirBase . Setup ( d => d . EnumerateDirectories ( rootPath ) )
677
- . Returns ( new [ ]
692
+ . Returns ( ( ) =>
678
693
{
679
- Path . Combine ( rootPath , "bin" ) ,
680
- Path . Combine ( rootPath , "function1" ) ,
681
- Path . Combine ( rootPath , "function2" ) ,
682
- 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
+ }
683
708
} ) ;
684
709
685
710
_function1 = @"{
0 commit comments