예제 #1
0
        public async Task TestThread()
        {
            var sw = Stopwatch.StartNew();
            await Simultaneously.Run(2, () => Sleep("test"));

            sw.ElapsedMilliseconds.ShouldBeInRange(100, 150);
        }
예제 #2
0
        public async Task TestManyThreads()
        {
            var boolean = new AtomicBool();

            var threads = await Simultaneously.Run(100, boolean.WasFalse);

            threads.Where(x => x).ShouldHaveSingleItem();
        }
        public async Task TestInitializesOnlyOnce()
        {
            var spy       = Spy.On(() => Delay("updated value"));
            var updatable = new BackgroundUpdatable <string>(
                TimeSpan.FromMinutes(10),
                spy.Func);

            var results = await Simultaneously.Run(5, updatable.Value);

            results.ShouldAllBe(x => x == "updated value");

            spy.Called.ShouldBe(1);
        }
예제 #4
0
        public async Task TestWithSlowFactory()
        {
            var counter = 0;

            var lazy = new AtomicLazy <string>(() =>
            {
                Interlocked.Increment(ref counter);
                return(Delay("result"));
            });

            await Simultaneously.Run(100, () => lazy.Value);

            lazy.Value.ShouldBe("result");

            counter.ShouldBe(1);
        }
        public async Task TestUpdatesOnlyOnce()
        {
            var spy       = Spy.On(() => Delay("updated value"));
            var updatable = new BackgroundUpdatable <string>(
                "initial value",
                TimeSpan.FromMilliseconds(100),
                spy.Func);

            updatable.Value();

            await Task.Delay(120);

            await Simultaneously.Run(50, updatable.Value);

            spy.Called.ShouldBe(1);
        }