Exemple #1
0
        public void TransmitConfigOptionWorks()
        {
            this.Reset();

            RollbarConfig config = this.ProvideLiveRollbarConfig() as RollbarConfig;

            using (IRollbar rollbar = this.ProvideDisposableRollbar())
            {
                rollbar.Configure(config);
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.Critical("Transmission is expected to happen!");
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.AsBlockingLogger(TimeSpan.FromSeconds(3)).Critical("Transmission is expected to happen!");

                config.Transmit = false;
                rollbar.Configure(config);
                this.IncrementCount <TransmissionOmittedEventArgs>();
                rollbar.Critical("Transmission is expected to be omitted!");
                this.IncrementCount <TransmissionOmittedEventArgs>();
                rollbar.AsBlockingLogger(TimeSpan.FromSeconds(3)).Critical("Transmission is expected to be omitted!");

                config.Transmit = true;
                rollbar.Configure(config);
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.Critical("Transmission is expected to happen!");
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.AsBlockingLogger(TimeSpan.FromSeconds(3)).Critical("Transmission is expected to happen!");
            }
        }
Exemple #2
0
        public void AllowsProxySettingsReconfiguration()
        {
            using (IRollbar logger = RollbarFactory.CreateNew().Configure(this._loggerConfig))
            {
                Assert.AreNotSame(this._loggerConfig, logger.Config);
                logger.Configure(this._loggerConfig);
                Assert.AreNotSame(this._loggerConfig, logger.Config);

                int errorCount = 0;
                logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Info("test 1");
                this.ExpectedCommunicationEventsTotal++;
                Assert.AreEqual(0, errorCount);

                RollbarConfig newConfig = new RollbarConfig("seed");
                newConfig.Reconfigure(this._loggerConfig);
                Assert.AreNotSame(this._loggerConfig, newConfig);
                logger.Configure(newConfig);
                logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Info("test 2");
                this.ExpectedCommunicationEventsTotal++;
                Assert.AreEqual(0, errorCount);

                newConfig.ProxyAddress  = "www.fakeproxy.com";
                newConfig.ProxyUsername = "******";
                newConfig.ProxyPassword = "******";
                logger.Configure(newConfig);
                Assert.IsFalse(string.IsNullOrEmpty(logger.Config.ProxyAddress));
                Assert.IsFalse(string.IsNullOrEmpty(logger.Config.ProxyUsername));
                Assert.IsFalse(string.IsNullOrEmpty(logger.Config.ProxyPassword));
                try
                {
                    // the fake proxy settings will cause a timeout exception here:
                    this.ExpectedCommunicationErrorsTotal++;
                    logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Info("test 3 with fake proxy");
                }
                catch
                {
                    errorCount++;
                }
                Assert.AreEqual(1, errorCount);

                newConfig.ProxyAddress  = null;
                newConfig.ProxyUsername = null;
                newConfig.ProxyPassword = null;
                logger.Configure(newConfig);
                Assert.IsTrue(string.IsNullOrEmpty(logger.Config.ProxyAddress));
                Assert.IsTrue(string.IsNullOrEmpty(logger.Config.ProxyUsername));
                Assert.IsTrue(string.IsNullOrEmpty(logger.Config.ProxyPassword));
                try
                {
                    // the fake proxy settings are gone, so, next call is expected to succeed:
                    this.ExpectedCommunicationEventsTotal++;
                    logger.AsBlockingLogger(TimeSpan.FromSeconds(15)).Info("test 4");
                }
                catch
                {
                    errorCount++;
                }
                Assert.AreEqual(1, errorCount);
            }
        }
Exemple #3
0
        public void RethrowConfigOptionWorks()
        {
            this.Reset();

            RollbarConfig config = this.ProvideLiveRollbarConfig() as RollbarConfig;

            using (IRollbar rollbar = this.ProvideDisposableRollbar())
            {
                rollbar.Configure(config);
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.Critical(ExceptionSimulator.GetExceptionWith(5, "Exception logged async!"));
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.AsBlockingLogger(TimeSpan.FromSeconds(3))
                .Critical(ExceptionSimulator.GetExceptionWith(5, "Exception logged sync!"));

                int rethrowCount = 0;
                config.RethrowExceptionsAfterReporting = true;
                rollbar.Configure(config);
                try
                {
                    this.IncrementCount <CommunicationEventArgs>();
                    rollbar.Critical(ExceptionSimulator.GetExceptionWith(5, "Exception logged async with rethrow!"));
                }
                catch
                {
                    rethrowCount++;
                }

                try
                {
                    this.IncrementCount <CommunicationEventArgs>();
                    rollbar.AsBlockingLogger(TimeSpan.FromSeconds(3))
                    .Critical(ExceptionSimulator.GetExceptionWith(5, "Exception logged sync with rethrow!"));
                }
                catch
                {
                    rethrowCount++;
                }

                config.RethrowExceptionsAfterReporting = false;
                rollbar.Configure(config);
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.Critical(ExceptionSimulator.GetExceptionWith(5, "Exception logged async!"));
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.AsBlockingLogger(TimeSpan.FromSeconds(3))
                .Critical(ExceptionSimulator.GetExceptionWith(5, "Exception logged sync!"));

                Assert.AreEqual(2, rethrowCount, "matching total of rethrows...");
            }
        }
        public void FaultyTruncateTest()
        {
            this.Reset();

            RollbarLoggerConfig config = this.ProvideLiveRollbarConfig() as RollbarLoggerConfig;
            RollbarPayloadManipulationOptions payloadManipulationOptions = new RollbarPayloadManipulationOptions();

            payloadManipulationOptions.Truncate = delegate(Payload payload)
            {
                throw new Exception("Buggy truncate delegate!");
            };
            config.RollbarPayloadManipulationOptions.Reconfigure(payloadManipulationOptions);

            using (IRollbar rollbar = this.ProvideDisposableRollbar())
            {
                rollbar.Configure(config);

                rollbar.Critical("This message's Truncate will fail!");

                this.VerifyInstanceOperational(rollbar);
                // one more extra sanity check:
                Assert.AreEqual(0, RollbarQueueController.Instance.GetTotalPayloadCount());
            }

            this.Reset();
        }
Exemple #5
0
        public void FaultyCheckIgnoreTest()
        {
            this.Reset();

            RollbarConfig config = this.ProvideLiveRollbarConfig() as RollbarConfig;

            config.CheckIgnore = delegate(Payload payload)
            {
                throw new Exception("Buggy check-ignore delegate!");
            };

            using (IRollbar rollbar = this.ProvideDisposableRollbar())
            {
                rollbar.Configure(config);

                rollbar.Critical("This message's CheckIgnore will fail!");

                this.VerifyInstanceOperational(rollbar);
                // one more extra sanity check:
                Assert.AreEqual(0, RollbarQueueController.Instance.GetTotalPayloadCount());
            }

            this.Reset();
        }
Exemple #6
0
        public void AllowsProxySettingsReconfiguration()
        {
            this.Reset();

            using (IRollbar logger = this.ProvideDisposableRollbar())
            {
                IRollbarConfig initialConfig = logger.Config;

                Assert.AreSame(initialConfig, logger.Config);
                logger.Configure(initialConfig);
                Assert.AreSame(initialConfig, logger.Config);

                int errorCount = 0;
                logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Info("test 1");
                this.IncrementCount <CommunicationEventArgs>();
                Assert.AreEqual(0, errorCount);

                RollbarConfig newConfig = new RollbarConfig("seed");
                newConfig.Reconfigure(initialConfig);
                Assert.AreNotSame(initialConfig, newConfig);
                logger.Configure(newConfig);
                logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Info("test 2");
                this.IncrementCount <CommunicationEventArgs>();
                Assert.AreEqual(0, errorCount);

                newConfig.ProxyAddress  = "www.fakeproxy.com";
                newConfig.ProxyUsername = "******";
                newConfig.ProxyPassword = "******";
                logger.Configure(newConfig);
                Assert.IsFalse(string.IsNullOrEmpty(logger.Config.ProxyAddress));
                Assert.IsFalse(string.IsNullOrEmpty(logger.Config.ProxyUsername));
                Assert.IsFalse(string.IsNullOrEmpty(logger.Config.ProxyPassword));
                try
                {
                    // the fake proxy settings will cause a timeout exception here:
                    this.IncrementCount <CommunicationErrorEventArgs>();
                    logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Info("test 3 with fake proxy");
                }
                catch
                {
                    errorCount++;
                }
                Assert.AreEqual(1, errorCount);

                newConfig.ProxyAddress  = null;
                newConfig.ProxyUsername = null;
                newConfig.ProxyPassword = null;
                logger.Configure(newConfig);
                Assert.IsTrue(string.IsNullOrEmpty(logger.Config.ProxyAddress));
                Assert.IsTrue(string.IsNullOrEmpty(logger.Config.ProxyUsername));
                Assert.IsTrue(string.IsNullOrEmpty(logger.Config.ProxyPassword));
                try
                {
                    // the fake proxy settings are gone, so, next call is expected to succeed:
                    this.IncrementCount <CommunicationEventArgs>();
                    logger.AsBlockingLogger(TimeSpan.FromSeconds(15)).Info("test 4");
                }
                catch
                {
                    errorCount++;
                }
                Assert.AreEqual(1, errorCount);
            }
        }