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);
        }
Esempio n. 2
0
 public void MatchWindow(string testId, MatchWindowData data, TaskListener <MatchResult> listener)
 {
     try
     {
         Logger.Log(TraceLevel.Info, testId, Stage.Check, StageType.MatchStart, new { matchWindowData = data });
         LoggingListener <MatchResult> loggingListener = new LoggingListener <MatchResult>(listener, Logger, testId);
         ServerConnector.MatchWindow(loggingListener, data, testId);
     }
     catch (Exception ex)
     {
         CommonUtils.LogExceptionStackTrace(Logger, Stage.Check, StageType.MatchComplete, ex, testId);
         listener.OnFail(ex);
     }
 }
        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);
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
        public void TryUploadImage(string testId, MatchWindowData data, TaskListener taskListener)
        {
            AppOutput appOutput = data.AppOutput;

            if (appOutput.ScreenshotUrl != null)
            {
                taskListener.OnComplete();
                return;
            }

            // Getting the screenshot bytes
            TaskListener <string> uploadListener = new TaskListener <string>(
                (url) =>
            {
                if (url == null)
                {
                    Logger.Verbose("Got null url from upload. Test id: {0}", testId);
                    appOutput.ScreenshotUrl = null;
                    taskListener.OnFail(new EyesException("Failed uploading image"));
                    return;
                }
                Logger.Log(TraceLevel.Info, testId, Stage.Check, StageType.UploadComplete, new { url });
                appOutput.ScreenshotUrl = url;
                appOutput.ClearScreenshotBytes();
                taskListener.OnComplete();
            },
                (ex) =>
            {
                appOutput.ScreenshotUrl = null;
                taskListener.OnFail(new EyesException("Failed uploading image", ex));
            }
                );

            try
            {
                Logger.Log(TraceLevel.Info, testId, Stage.Check, StageType.UploadStart,
                           new { dataLength = appOutput.ScreenshotBytes.Length });
                ServerConnector.UploadImage(uploadListener, appOutput.ScreenshotBytes, testId);
            }
            catch (Exception ex)
            {
                taskListener.OnFail(ex);
            }
        }
Esempio n. 6
0
 public EnabledBatchClose(Logger logger, Uri serverUrl, IEnumerable <string> batchIds) : base(logger)
 {
     serverConnector_ = new ServerConnector(logger);
     ServerUrl        = serverUrl;
     batchIds_        = batchIds;
 }