public void CanInterruptLongSleep() { // given var expected = 101717; var target = new BeaconSendingContext(logger, config, clientProvider, timingProvider); target.RequestShutdown(); target.Sleep(expected); // then #if !NETCOREAPP1_0 || !NETCOREAPP1_1 // normal sleep as thread interrupt exception exists timingProvider.Received(1).Sleep(expected); #else // no interrupt exception exists, therefore "sliced" sleep break after first iteration timingProvider.Received(1).Sleep(Arg.Any <int>()); timingProvider.Received(1).Sleep(BeaconSendingContext.DEFAULT_SLEEP_TIME_MILLISECONDS); #endif }
public void CanSleepLonger() { // given var expected = 101717; var target = new BeaconSendingContext(logger, config, clientProvider, timingProvider); target.Sleep(expected); // then #if !NETCOREAPP1_0 || !NETCOREAPP1_1 // normal sleep as thread interrupt exception exists timingProvider.Received(1).Sleep(expected); #else // no interrupt exception exists, therefore "sliced" sleeps until total sleep amount var expectedCount = (int)Math.Ceiling(expected / (double)BeaconSendingContext.DEFAULT_SLEEP_TIME_MILLISECONDS); timingProvider.Received(expectedCount).Sleep(Arg.Any <int>()); timingProvider.Received(expectedCount - 1).Sleep(BeaconSendingContext.DEFAULT_SLEEP_TIME_MILLISECONDS); timingProvider.Received(1).Sleep(expected % BeaconSendingContext.DEFAULT_SLEEP_TIME_MILLISECONDS); #endif }