Skip to content

Commit

Permalink
Changing CompositeListener to start/stop all listeners in parallel. T…
Browse files Browse the repository at this point in the history
…his improves startup times in general, particularly for Singleton listeners.
  • Loading branch information
mathewc committed Oct 21, 2015
1 parent c15d031 commit ddf2acf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Microsoft.Azure.WebJobs.Host/Listeners/CompositeListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,28 @@ public async Task StartAsync(CancellationToken cancellationToken)
{
ThrowIfDisposed();

// start all listeners in parallel
List<Task> tasks = new List<Task>();
foreach (IListener listener in _listeners)
{
await listener.StartAsync(cancellationToken);
tasks.Add(listener.StartAsync(cancellationToken));
}

await Task.WhenAll(tasks);
}

public async Task StopAsync(CancellationToken cancellationToken)
{
ThrowIfDisposed();

// stop all listeners in parallel
List<Task> tasks = new List<Task>();
foreach (IListener listener in _listeners)
{
await listener.StopAsync(cancellationToken);
tasks.Add(listener.StopAsync(cancellationToken));
}

await Task.WhenAll(tasks);
}

public void Cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Threading;
using Xunit;

namespace Microsoft.Azure.WebJobs.Host.UnitTests.Singleton
Expand Down Expand Up @@ -92,5 +93,28 @@ public void LockAcquisitionTimeout_RangeValidation()
Assert.Equal(value, config.LockAcquisitionTimeout);
}
}

[Fact]
public void ListenerLockRecoveryPollingInterval_RangeValidation()
{
SingletonConfiguration config = new SingletonConfiguration();

Assert.Throws<ArgumentOutOfRangeException>(() =>
{
config.ListenerLockRecoveryPollingInterval = TimeSpan.FromMilliseconds(14999);
});

TimeSpan[] validValues = new TimeSpan[]
{
Timeout.InfiniteTimeSpan,
TimeSpan.FromSeconds(15),
TimeSpan.FromMinutes(5)
};
foreach (TimeSpan value in validValues)
{
config.ListenerLockRecoveryPollingInterval = value;
Assert.Equal(value, config.ListenerLockRecoveryPollingInterval);
}
}
}
}

0 comments on commit ddf2acf

Please sign in to comment.