Beispiel #1
0
        public void Operate(string testId, SessionStartInfo sessionStartInfo, TaskListener <RunningSession> listener)
        {
            Logger.Log(TraceLevel.Notice, testId, Stage.Open, new { sessionStartInfo.AgentSessionId });
            Stopwatch stopwatch = Stopwatch.StartNew();

            TaskListener <RunningSession> taskListener = new TaskListener <RunningSession>(
                (runningSession) => OnComplete_(sessionStartInfo, listener, runningSession, stopwatch, testId),
                (ex) =>
            {
                var webEx = CommonUtils.GetInnerException <WebException>(ex);
                if (webEx != null && webEx.Status != WebExceptionStatus.Success)
                {
                    CommonUtils.LogExceptionStackTrace(Logger, Stage.Open, ex,
                                                       new { webExceptionStatus = webEx.Status }, testId);
                    listener.OnFail(ex.InnerException);
                    return;
                }
                OnFail_(stopwatch, sessionStartInfo, listener, testId);
            }
                );

            try
            {
                ServerConnector.StartSession(taskListener, sessionStartInfo);
            }
            catch (Exception e)
            {
                listener.OnFail(e);
            }
        }
        public void TestLongRequest_SimplePoll()
        {
            Logger          logger          = new Logger();
            ServerConnector serverConnector = new ServerConnector(logger);

            serverConnector.ServerUrl = new Uri(CommonData.DefaultServerUrl);
            MockHttpRestClientFactory mockHttpRestClientFactory = new MockHttpRestClientFactory(
                logger,
                new int?[] { 2, null, 3 },
                new string[] { CommonData.DefaultServerUrl + "url1", null, CommonData.DefaultServerUrl + "url2" });

            serverConnector.HttpRestClientFactory = mockHttpRestClientFactory;
            serverConnector.ApiKey = "testKey";

            SessionStartInfo startInfo = GetStartInfo();
            RunningSession   result    = serverConnector.StartSession(startInfo);

            var             requestCreator = mockHttpRestClientFactory.Provider.Handler;
            List <string>   requests       = requestCreator.RequestUrls;
            List <TimeSpan> timings        = requestCreator.Timings;

            Assert.AreEqual(6, requests.Count);
            Assert.AreEqual(6, timings.Count);
            StringAssert.StartsWith(CommonData.DefaultServerUrl + "api/sessions/running", requests[0]);
            StringAssert.StartsWith(CommonData.DefaultServerUrl + BASE_LOCATION + "status", requests[1]);

            StringAssert.StartsWith(CommonData.DefaultServerUrl + "url1", requests[2]);
            Assert.Greater(timings[2], TimeSpan.FromSeconds(2));

            StringAssert.StartsWith(CommonData.DefaultServerUrl + "url1", requests[3]);
            Assert.Greater(timings[3], TimeSpan.FromSeconds(0.5));

            StringAssert.StartsWith(CommonData.DefaultServerUrl + "url2", requests[4]);
            Assert.Greater(timings[4], TimeSpan.FromSeconds(3));
        }
        public void TestStartSession_LongRequest_IsNewField(bool isNew)
        {
            Logger          logger          = new Logger();
            ServerConnector serverConnector = new ServerConnector(logger);

            serverConnector.ServerUrl             = new Uri(CommonData.DefaultServerUrl);
            serverConnector.HttpRestClientFactory = new MockHttpRestClientFactory(isNew: isNew);
            serverConnector.ApiKey = "testKey";
            SessionStartInfo startInfo = GetStartInfo();
            RunningSession   result    = serverConnector.StartSession(startInfo);

            Assert.AreEqual(isNew, result.IsNewSession);
        }
        public void TestStartSession_LongRequest_StatusCode(HttpStatusCode statusCode)
        {
            Logger          logger          = new Logger();
            ServerConnector serverConnector = new ServerConnector(logger);

            serverConnector.ServerUrl             = new Uri(CommonData.DefaultServerUrl);
            serverConnector.HttpRestClientFactory = new MockHttpRestClientFactory(statusCode: statusCode);
            serverConnector.ApiKey = "testKey";
            SessionStartInfo startInfo = GetStartInfo();
            RunningSession   result    = serverConnector.StartSession(startInfo);

            bool isNew = statusCode == HttpStatusCode.Created;

            Assert.AreEqual(isNew, result.IsNewSession);
        }
Beispiel #5
0
        private void OnFail_(Stopwatch stopwatch, SessionStartInfo sessionStartInfo, TaskListener <RunningSession> listener, string testId)
        {
            TimeSpan sleepDuration = TimeSpan.FromSeconds(2);

            if (stopwatch.Elapsed > TIME_TO_WAIT_FOR_OPEN)
            {
                isServerConcurrencyLimitReached_ = false;
                listener.OnFail(new EyesException("Timeout in start session"));
                return;
            }

            try
            {
                Thread.Sleep(sleepDuration);
                if (stopwatch.Elapsed.TotalSeconds >= 30)
                {
                    sleepDuration = TimeSpan.FromSeconds(10);
                }
                else if (stopwatch.Elapsed.TotalSeconds >= 10)
                {
                    sleepDuration = TimeSpan.FromSeconds(5);
                }

                Logger.Verbose("Trying startSession again");
                ServerConnector.StartSession(
                    new TaskListener <RunningSession>(
                        (runningSession) => OnComplete_(sessionStartInfo, listener, runningSession, stopwatch, testId),
                        (ex) =>
                {
                    var socketEx = CommonUtils.GetInnerException <SocketException>(ex);
                    if (socketEx != null && socketEx.SocketErrorCode == SocketError.ConnectionRefused)
                    {
                        listener.OnFail(ex.InnerException);
                        return;
                    }

                    OnFail_(stopwatch, sessionStartInfo, listener, testId);
                }
                        ),
                    sessionStartInfo);
            }
            catch (Exception e)
            {
                CommonUtils.LogExceptionStackTrace(Logger, Stage.Open, StageType.Retry, e, testId);
                listener.OnFail(e);
            }
        }