Ejemplo n.º 1
0
        protected BaseTest(ILogAdapter extraLogging)
        {
            LogCapture  = Logs.Capture();
            TestLogging = Logs.ToMultiple(extraLogging, LogCapture);
            TestLogger  = TestLogging.Logger("");

            BasicContext = new LdClientContext(new BasicConfiguration(Configuration.Default(BasicSdkKey), TestLogger),
                                               Configuration.Default(""));

            BasicTaskExecutor = new TaskExecutor("test-sender", TestLogger);

            // The following line prevents intermittent test failures that happen only in .NET
            // Framework, where background tasks (including calls to Task.Delay) are very excessively
            // slow to start-- on the order of many seconds. The issue appears to be a long-standing
            // one that is described here, where the very low default setting of ThreadPool.SetMinThreads
            // causes new worker tasks to be severely throttled:
            // http://joeduffyblog.com/2006/07/08/clr-thread-pool-injection-stuttering-problems/
            //
            // We've seen experimentally that this setting defaults to 2 when running the tests in .NET
            // Framework, versus at least 12 when running them in .NET Core.
            //
            // It is theoretically possible for something similar to happen in a real application, but
            // since that would affect all tasks in the application, we assume that developers would
            // need to tune this parameter in any case, not only because of our SDK.
            ThreadPool.SetMinThreads(100, 100);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Use this constructor if you want to be able to send logs to the Xunit test output buffer.
 /// Xunit will pass the <see cref="ITestOutputHelper"/> to the test subclass's constructor
 /// if you declare a parameter of that type.
 /// </summary>
 /// <param name="testOutput"></param>
 public BaseTest(ITestOutputHelper testOutput) : this()
 {
     _testLogging = Logs.ToMultiple(
         Logs.ToMethod(testOutput.WriteLine),
         _logCapture
         );
     _testLogger = _testLogging.Logger("");
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Default constructor - does not use the Xunit test output buffer.
        /// </summary>
        public BaseTest()
        {
            _logCapture  = Logs.Capture();
            _testLogging = _logCapture;
            _testLogger  = _testLogging.Logger("");

            // The following line prevents intermittent test failures that can happen due to the low
            // default setting of ThreadPool.SetMinThreads causing new worker tasks to be severely
            // throttled: http://joeduffyblog.com/2006/07/08/clr-thread-pool-injection-stuttering-problems/
            // This makes it difficult to test things such as timeouts. We believe it not to be a real
            // issue in non-test scenarios, since the tests are starting and stopping an unusually large
            // number of async tasks in a way that regular use of EventSource would not do.
            ThreadPool.SetMinThreads(100, 100);
        }
        private IBigSegmentStore MakeStore()
        {
            var context = new LdClientContext(new BasicConfiguration("sdk-key", false, _testLogging.Logger("")),
                                              LaunchDarkly.Sdk.Server.Configuration.Default("sdk-key"));

            return(Configuration.StoreFactoryFunc(prefix).CreateBigSegmentStore(context));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// This constructor allows log output to be captured by Xunit. Simply declare a constructor
 /// with the same <c>ITestOutputHelper</c> parameter for your test class and pass the parameter
 /// straight through to the base class constructor.
 /// </summary>
 /// <example>
 /// <code>
 ///     public class MyTestClass : BaseTest
 ///     {
 ///         public MyTestClass(ITestOutputHelper testOutput) : base(testOutput) { }
 ///     }
 /// </code>
 /// </example>
 /// <param name="testOutput">the <see cref="ITestOutputHelper"/> that Xunit passed to the test
 /// class constructor</param>
 public BaseTest(ITestOutputHelper testOutput) : this()
 {
     testLogging = Logs.ToMultiple(TestLogging.TestOutputAdapter(testOutput), logCapture);
     testLogger  = testLogging.Logger("");
 }