private void RunPlayerTest(string clipTitle, Func <TestContext, Task> testImpl) { AsyncContext.Run(async() => { _logger.Info($"Begin: {NUnit.Framework.TestContext.CurrentContext.Test.FullName}"); using (var cts = new CancellationTokenSource()) { using (var service = new PlayerService()) { try { var context = new TestContext { Service = service, ClipTitle = clipTitle, Token = cts.Token, // Requested seek position may differ from // seek position issued to player. Difference can be 10s+ // Encrypted streams (Widevine in particular) may have LONG license // installation times (10s+). // DRM content has larger timeout Timeout = TSPlayerServiceTestCaseSource.IsEncrypted(clipTitle) ? TimeSpan.FromSeconds(40) : TimeSpan.FromSeconds(20) }; var prepareOperation = new PrepareOperation(); prepareOperation.Prepare(context); await prepareOperation.Execute(context); var startOperation = new StartOperation(); startOperation.Prepare(context); await startOperation.Execute(context); await testImpl(context); } catch (Exception e) { _logger.Error($"Error: {NUnit.Framework.TestContext.CurrentContext.Test.FullName} {e.Message} {e.StackTrace}"); throw; } // Test completed. Cancel token to kill any test's sub activities. // Do so before PlayerService gets destroyed (in case those activities access it) cts.Cancel(); } } _logger.Info($"End: {NUnit.Framework.TestContext.CurrentContext.Test.FullName}"); }); }
public void Playback_StartFromThe90thSecond_PreparesAndStarts(string clipTitle) { RunPlayerTest(clipTitle, async context => { context.SeekTime = TimeSpan.FromSeconds(90); var seekOperation = new SeekOperation(); seekOperation.Prepare(context); var seek = seekOperation.Execute(context); var startOperation = new StartOperation(); startOperation.Prepare(context); await startOperation.Execute(context); await seek; }, false); }