Bound bouquet lookup and preserve playback if OpenWebif is unavailable
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
@@ -54,6 +55,14 @@ public static class SavedChannelPlaybackTests
|
||||
using var cancelled=new CancellationTokenSource();cancelled.Cancel();
|
||||
try { await service.GetChannelStream(Old,null,cancelled.Token);throw new Exception("Expected cancellation"); }
|
||||
catch(OperationCanceledException) { check(handler.Calls==1,"cancelled channel lookup opens no extra upstream"); }
|
||||
|
||||
var offline=new LiveTvService(NullLogger<LiveTvService>.Instance,new ReceiverFactory(new UnavailableBouquet(false)),null,probe,relay,library);
|
||||
check((await offline.GetChannelStream(Current,null,CancellationToken.None)).Path==current.Path&&((SavedChannelLibrary)(object)library).Calls==1,
|
||||
"unavailable web interface preserves direct playback without historical lookup");
|
||||
var stalled=new LiveTvService(NullLogger<LiveTvService>.Instance,new ReceiverFactory(new UnavailableBouquet(true)),null,probe,relay,library);
|
||||
var watch=Stopwatch.StartNew();
|
||||
check((await stalled.GetChannelStream(Current,null,CancellationToken.None)).Path==current.Path&&watch.Elapsed<TimeSpan.FromSeconds(7),
|
||||
"stalled bouquet lookup is bounded to five seconds and preserves requested playback");
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -89,7 +98,19 @@ public static class SavedChannelPlaybackTests
|
||||
}
|
||||
private sealed class ReceiverFactory:IHttpClientFactory
|
||||
{
|
||||
public HttpClient CreateClient(string name)=>new(new BouquetHandler());
|
||||
private readonly HttpMessageHandler handler;
|
||||
public ReceiverFactory(HttpMessageHandler handler=null){this.handler=handler;}
|
||||
public HttpClient CreateClient(string name)=>new(handler??new BouquetHandler());
|
||||
}
|
||||
private sealed class UnavailableBouquet:HttpMessageHandler
|
||||
{
|
||||
private readonly bool stall;
|
||||
public UnavailableBouquet(bool stall){this.stall=stall;}
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,CancellationToken token)
|
||||
{
|
||||
if(stall)await Task.Delay(Timeout.InfiniteTimeSpan,token);
|
||||
throw new HttpRequestException("Receiver web interface unavailable");
|
||||
}
|
||||
}
|
||||
private sealed class BouquetHandler:HttpMessageHandler
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user