示例#1
0
        public void RetryConnectionErrorTestNetStandard20()
        {
            Stopwatch watch = new Stopwatch();

            // Set invalid host address and make timeout to 1s
            var config = new RudderConfig().SetAsync(false);

            config.SetHost("https://fake.rudder-server.com");
            config.SetTimeout(new TimeSpan(0, 0, 1));
            config.SetMaxRetryTime(new TimeSpan(0, 0, 10));
            RudderAnalytics.Initialize(Constants.WRITE_KEY, config);

            // Calculate working time for Identiy message with invalid host address
            watch.Start();
            Actions.Identify(RudderAnalytics.Client);
            watch.Stop();

            Assert.AreEqual(1, RudderAnalytics.Client.Statistics.Submitted);
            Assert.AreEqual(0, RudderAnalytics.Client.Statistics.Succeeded);
            Assert.AreEqual(1, RudderAnalytics.Client.Statistics.Failed);

            // Handling Identify message will take more than 10s even though the timeout is 1s.
            // That's because it retries submit when it's failed.
            Assert.AreEqual(true, watch.ElapsedMilliseconds > 10000);
        }
示例#2
0
        private static void OnExecute(string writeKey)
        {
            var config = new RudderConfig()
                         .SetMaxQueueSize(100000)
                         .SetHost("https://hosted.rudderlabs.com")
                         .SetMaxBatchSize(40);

            //.SetRequestCompression(true);

            RudderAnalytics.Initialize(writeKey, config);

            Logger.Handlers += Utils.LoggerOnHandlers;

            for (var i = 0; i < UserJourneys; i++)
            {
                Utils.DoJourney();
            }

            // sending all pendant messages
            RudderAnalytics.Client.Flush();

            Utils.PrintSummary();

            RudderAnalytics.Client.Dispose();
        }
示例#3
0
        public async Task PerformanceTestNetStandard20()
        {
            var client = new RudderClient(Constants.WRITE_KEY, new RudderConfig(), _mockRequestHandler.Object);

            RudderAnalytics.Initialize(client);

            RudderAnalytics.Client.Succeeded += Client_Succeeded;
            RudderAnalytics.Client.Failed    += Client_Failed;

            int trials = 100;

            DateTime start = DateTime.Now;

            RunTests(RudderAnalytics.Client, trials);

            await RudderAnalytics.Client.FlushAsync();

            TimeSpan duration = DateTime.Now.Subtract(start);

            Assert.AreEqual(trials, RudderAnalytics.Client.Statistics.Submitted);
            Assert.AreEqual(trials, RudderAnalytics.Client.Statistics.Succeeded);
            Assert.AreEqual(0, RudderAnalytics.Client.Statistics.Failed);

            Assert.IsTrue(duration.CompareTo(TimeSpan.FromSeconds(20)) < 0);
        }
示例#4
0
        static void Main(string[] args)
        {
            Logger.Handlers += Logger_Handlers;

            RudderAnalytics.Initialize(RudderStack.Test.Constants.WRITE_KEY);

            RudderAnalytics.Client.Track("prateek", "Item Purchased (with .Net 3.5)");
            RudderAnalytics.Client.Flush();
        }
示例#5
0
        static void Main_Exe(string[] args)
        {
            Logger.Handlers += Logger_Handlers;

            //Analytics.Initialize(RudderStack.Test.Constants.WRITE_KEY);

            //FlushTests tests = new FlushTests();
            //tests.PerformanceTest().Wait();
            RudderAnalytics.Initialize("1sCR76JzHpQohjl33pi8qA5jQD2", new RudderConfig(dataPlaneUrl: "https://75652af01e6d.ngrok.io"));
            RudderAnalytics.Client.Track("prateek", "Item Purchased");
            RudderAnalytics.Client.Flush();
        }
示例#6
0
        public void GZipTestNetStanard20()
        {
            // Set proxy address, like as "http://localhost:8888"
            var client = new RudderClient(Constants.WRITE_KEY, new RudderConfig().SetAsync(false), _mockRequestHandler.Object);

            RudderAnalytics.Initialize(client);

            Actions.Identify(RudderAnalytics.Client);

            Assert.AreEqual(1, RudderAnalytics.Client.Statistics.Submitted);
            Assert.AreEqual(1, RudderAnalytics.Client.Statistics.Succeeded);
            Assert.AreEqual(0, RudderAnalytics.Client.Statistics.Failed);
        }
        public void GZipTestNet35()
        {
            // Set GZip/Deflate on request header
            var client = new RudderClient(Constants.WRITE_KEY, new RudderConfig().SetAsync(false), _mockRequestHandler.Object);

            RudderAnalytics.Initialize(client);

            Actions.Identify(RudderAnalytics.Client);

            Assert.AreEqual(1, RudderAnalytics.Client.Statistics.Submitted);
            Assert.AreEqual(1, RudderAnalytics.Client.Statistics.Succeeded);
            Assert.AreEqual(0, RudderAnalytics.Client.Statistics.Failed);
        }
示例#8
0
        public void Init()
        {
            _mockRequestHandler = new Mock <IRequestHandler>();
            _mockRequestHandler
            .Setup(x => x.MakeRequest(It.IsAny <Batch>()))
            .Returns(async(Batch b) =>
            {
                b.batch.ForEach(_ => RudderAnalytics.Client.Statistics.IncrementSucceeded());
            });

            RudderAnalytics.Dispose();
            var client = new RudderClient(Constants.WRITE_KEY, new RudderConfig().SetAsync(false), _mockRequestHandler.Object);

            RudderAnalytics.Initialize(client);
        }
示例#9
0
        static void Main(string[] args)
        {
            Logger.Handlers += Logger_Handlers;

            //Analytics.Initialize(RudderStack.Test.Constants.WRITE_KEY);

            //FlushTests tests = new FlushTests();
            //tests.PerformanceTestNet45();
            RudderAnalytics.Initialize("1sCR76JzHpQohjl33pi8qA5jQD2", new RudderConfig(dataPlaneUrl: "https://75652af01e6d.ngrok.io"));
            RudderAnalytics.Client.Identify(
                "userId",
                new Dictionary <string, object> {
                { "subscription", "inactive" },
            }
                );
            RudderAnalytics.Client.Track(
                "userId",
                "CTA Clicked",
                new Dictionary <string, object>
            {
                { "plan", "premium" },
            }
                );
            RudderAnalytics.Client.Page(
                "userId",
                "Sign Up",
                new Dictionary <string, object> {
                { "url", "https://wwww.example.com/sign-up" },
            }
                );
            RudderAnalytics.Client.Screen(
                "userId",
                "Dashboard",
                new Dictionary <string, object> {
                { "name", "Paid Dashboard" },
            }
                );
            RudderAnalytics.Client.Group(
                "userId",
                "accountId",
                new Dictionary <string, object> {
                { "role", "Owner" },
            }
                );
            RudderAnalytics.Client.Alias("anonUserId", "userId");

            RudderAnalytics.Client.Flush();
        }
示例#10
0
        public void SynchronousFlushTestNetStandard20()
        {
            var client = new RudderClient(Constants.WRITE_KEY, new RudderConfig().SetAsync(false), _mockRequestHandler.Object);

            RudderAnalytics.Initialize(client);
            RudderAnalytics.Client.Succeeded += Client_Succeeded;
            RudderAnalytics.Client.Failed    += Client_Failed;

            int trials = 10;

            RunTests(RudderAnalytics.Client, trials);

            Assert.AreEqual(trials, RudderAnalytics.Client.Statistics.Submitted);
            Assert.AreEqual(trials, RudderAnalytics.Client.Statistics.Succeeded);
            Assert.AreEqual(0, RudderAnalytics.Client.Statistics.Failed);
        }
示例#11
0
        private static void OnExecute(string writeKey, string dataPlaneUrl)
        {
            //RudderAnalytics.Initialize(writeKey);

            RudderAnalytics.Initialize(writeKey, new RudderConfig(dataPlaneUrl: dataPlaneUrl));

            for (var i = 0; i < UserJourneys; i++)
            {
                Utils.DoJourney();
            }

            // sending all pendant messages
            RudderAnalytics.Client.Flush();

            Utils.PrintSummary();

            RudderAnalytics.Client.Dispose();
        }
示例#12
0
        public void HeaderTestNet35()
        {
            // Arrange: Init SDK:
            RudderAnalytics.Initialize(Constants.WRITE_KEY, new RudderConfig().SetAsync(false));

            // Act: Perform some tracking events:
            for (int i = 0; i < 10; i += 1)
            {
                RudderAnalytics.Client.Track("mockUserId", "mockEvent", new Properties(), new RudderOptions());
            }

            var flushHandler        = GetPrivateFieldByReflection(RudderAnalytics.Client, "_flushHandler");
            var requestHandler      = GetPrivateFieldByReflection(flushHandler, "_requestHandler");
            var httpClient          = GetPrivateFieldByReflection(requestHandler, "_httpClient") as WebClient;
            var authorizationHeader = httpClient.Headers.Get("Authorization");

            // Assert: Verify that "Basic" appears only once in the Authorization header:
            Assert.AreEqual(1, Regex.Matches(authorizationHeader, "Basic").Count);
        }
示例#13
0
        public void RetryServerErrorWithDefaultMaxRetryTimeTestNetStandard20()
        {
            Stopwatch watch          = new Stopwatch();
            string    DummyServerUrl = "http://localhost:8181";

            using (var DummyServer = new WebServer(DummyServerUrl))
            {
                // Set invalid host address and make timeout to 1s
                var config = new RudderConfig().SetAsync(false);
                config.SetHost(DummyServerUrl);
                config.SetTimeout(new TimeSpan(0, 0, 1));
                RudderAnalytics.Initialize(Constants.WRITE_KEY, config);

                var TestCases = new RetryErrorTestCase[]
                {
                    // The errors (500 > code >= 400) doesn't require retry
                    new RetryErrorTestCase()
                    {
                        ErrorMessage  = "Server Gone",
                        ResponseCode  = HttpStatusCode.Gone,
                        ShouldRetry   = false,
                        Timeout       = 10000,
                        BaseActionUrl = "/ServerGone"
                    },
                    // 429 error requires retry
                    new RetryErrorTestCase()
                    {
                        ErrorMessage  = "Too many requests",
                        ResponseCode  = (HttpStatusCode)429,
                        ShouldRetry   = true,
                        Timeout       = 10000,
                        BaseActionUrl = "/TooManyRequests"
                    },
                    // Server errors require retry
                    new RetryErrorTestCase()
                    {
                        ErrorMessage  = "Bad Gateway",
                        ResponseCode  = HttpStatusCode.BadGateway,
                        ShouldRetry   = true,
                        Timeout       = 10000,
                        BaseActionUrl = "/BadGateWay"
                    }
                };

                foreach (var testCase in TestCases)
                {
                    // Setup Action module which returns error code
                    var actionModule = new ActionModule(testCase.BaseActionUrl, HttpVerbs.Any, (ctx) =>
                    {
                        return(ctx.SendStandardHtmlAsync((int)testCase.ResponseCode));
                    });
                    DummyServer.WithModule(actionModule);
                }

                DummyServer.RunAsync();

                foreach (var testCase in TestCases)
                {
                    RudderAnalytics.Client.Config.SetHost(DummyServerUrl + testCase.BaseActionUrl);
                    // Calculate working time for Identiy message with invalid host address
                    watch.Reset();
                    watch.Start();
                    Actions.Identify(RudderAnalytics.Client);
                    watch.Stop();

                    Assert.AreEqual(0, RudderAnalytics.Client.Statistics.Succeeded);

                    // Handling Identify message will less than 10s because the server returns GONE message.
                    // That's because it retries submit when it's failed.
                    if (testCase.ShouldRetry)
                    {
                        Assert.IsTrue(watch.ElapsedMilliseconds > testCase.Timeout);
                    }
                    else
                    {
                        Assert.IsFalse(watch.ElapsedMilliseconds > testCase.Timeout);
                    }
                }
            }
        }
        public void RetryServerErrorWithDefaultMaxRetryTimeTestNet35()
        {
            Stopwatch watch = new Stopwatch();

            string DummyServerUrl = "http://localhost:9696";

            using (var DummyServer = new WebServer(DummyServerUrl))
            {
                DummyServer.RunAsync();

                // Set invalid host address and make timeout to 1s
                var config = new RudderConfig().SetAsync(false);
                config.SetHost(DummyServerUrl);
                config.SetTimeout(new TimeSpan(0, 0, 1));
                RudderAnalytics.Initialize(Constants.WRITE_KEY, config);

                var TestCases = new RetryErrorTestCase[]
                {
                    // The errors (500 > code >= 400) doesn't require retry
                    new RetryErrorTestCase()
                    {
                        ErrorMessage = "Server Gone",
                        ResponseCode = HttpStatusCode.Gone,
                        ShouldRetry  = false,
                        Timeout      = 10000
                    },
                    // 429 error requires retry
                    new RetryErrorTestCase()
                    {
                        ErrorMessage = "Too many requests",
                        ResponseCode = (HttpStatusCode)429,
                        ShouldRetry  = true,
                        Timeout      = 10000
                    },
                    // Server errors require retry
                    new RetryErrorTestCase()
                    {
                        ErrorMessage = "Bad Gateway",
                        ResponseCode = HttpStatusCode.BadGateway,
                        ShouldRetry  = true,
                        Timeout      = 10000
                    }
                };

                foreach (var testCase in TestCases)
                {
                    // Setup fallback module which returns error code
                    DummyServer.RequestHandler = ((req, res) =>
                    {
                        string pageData = "{ ErrorMessage: '" + testCase.ErrorMessage + "' }";
                        byte[] data = Encoding.UTF8.GetBytes(pageData);

                        res.StatusCode = (int)testCase.ResponseCode;
                        res.ContentType = "application/json";
                        res.ContentEncoding = Encoding.UTF8;
                        res.ContentLength64 = data.LongLength;

                        res.OutputStream.Write(data, 0, data.Length);
                        res.Close();
                    });

                    // Calculate working time for Identiy message with invalid host address
                    watch.Start();
                    Actions.Identify(RudderAnalytics.Client);
                    watch.Stop();

                    DummyServer.RequestHandler = null;

                    Assert.AreEqual(0, RudderAnalytics.Client.Statistics.Succeeded);

                    // Handling Identify message will less than 10s because the server returns GONE message.
                    // That's because it retries submit when it's failed.
                    if (testCase.ShouldRetry)
                    {
                        Assert.IsTrue(watch.ElapsedMilliseconds > testCase.Timeout);
                    }
                    else
                    {
                        Assert.IsFalse(watch.ElapsedMilliseconds > testCase.Timeout);
                    }
                }
            }
        }