Beispiel #1
0
        private void RunRandomOperationsTest(string clipTitle, IList <TestOperation> operations, bool shouldPrepare)
        {
            RunPlayerTest(clipTitle, async context =>
            {
                context.RandomMaxDelayTime = TimeSpan.FromSeconds(3);
                context.DelayTime          = TimeSpan.FromSeconds(2);
                context.Timeout            = TSPlayerServiceTestCaseSource.IsEncrypted(clipTitle) ? TimeSpan.FromSeconds(40) : TimeSpan.FromSeconds(20);

                if (shouldPrepare)
                {
                    foreach (var operation in operations)
                    {
                        _logger.Info($"Prepare: {operation}");
                        operation.Prepare(context);
                        _logger.Info($"Prepare Done: {operation}");
                    }
                }

                foreach (var operation in operations)
                {
                    _logger.Info($"Execute: {operation}");
                    await operation.Execute(context);
                    _logger.Info($"Execute Done: {operation}");
                }
            });
        }
Beispiel #2
0
        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}");
            });
        }