コード例 #1
0
ファイル: AppFlowTests.cs プロジェクト: r8zbeh/cscore
        public async Task TestDefaultAppFlowImplementation()
        {
            var tracker = new MyAppFlowTracker2(new InMemoryKeyValueStore().GetTypeAdapter <AppFlowEvent>());

            AppFlow.AddAppFlowTracker(tracker);
            Log.MethodEntered(); // This will internally notify the AppFlow instance
            Assert.NotEmpty(await tracker.store.GetAllKeys());

            var s = StopwatchV2.StartNewV2();

            for (int i = 0; i < 20; i++)
            {
                await TaskV2.Delay(500);

                if ((await tracker.store.GetAllKeys()).Count() == 0)
                {
                    break;
                }
            }
            Assert.True(s.ElapsedMilliseconds < 5000, "s.ElapsedMilliseconds=" + s.ElapsedMilliseconds);

            Assert.Empty(await tracker.store.GetAllKeys());
            // Make sure the DefaultAppFlowImpl itself does not create more events while sending the existing ones:
            for (int i = 0; i < 10; i++)
            {
                await TaskV2.Delay(100);

                var c1 = tracker.eventsThatWereSent.Count;
                await TaskV2.Delay(100);

                var c2 = tracker.eventsThatWereSent.Count;
                Assert.Equal(c1, c2);
            }
        }
コード例 #2
0
        public void TestLoggingMethodEndOnly2()
        {
            var s = StopwatchV2.StartNewV2("TestLoggingMethodEndOnly2");

            // ...
            Log.MethodDone(s);
        }
コード例 #3
0
ファイル: SystemTests.cs プロジェクト: cs-util-com/cscore
        public void TestGuidV2()
        {
            for (int i = 0; i < 1000; i++)
            {
                var a = GuidV2.NewGuid();
                var b = GuidV2.NewGuid();
                //Assert.True(b.CompareTo(a) > 0, $"Run {i}: a={a} was > then b={b}");
                Assert.True(b.CompareToV2(a) > 0, $"Run {i}: a={a} was > then b={b}");
                Assert.True(a.CompareToV2(b) < 0, $"Run {i}: a={a} was > then b={b}");
                Assert.True(a.CompareToV2(a) == 0, $"Run {i}: a != a : {b}");
            }
            var count = 1000000;
            var t1    = StopwatchV2.StartNewV2();

            {
                var isOrderedAfterCounter = RunIdTest(count, () => Guid.NewGuid());
                // Guid.NewGuid are not ordered:
                Assert.NotEqual(0, isOrderedAfterCounter);
                Assert.NotEqual(count, isOrderedAfterCounter);
            }
            t1.StopV2();
            var t2 = StopwatchV2.StartNewV2();

            {
                var isOrderedAfterCounter = RunIdTest(count, () => GuidV2.NewGuid());
                // GuidV2.NewGuid must be ordered:
                Assert.Equal(count, isOrderedAfterCounter);
            }
            t2.StopV2();
            // Check that the GuidV2.NewGuid is not much slower then Guid.NewGuid
            Assert.True(t1.ElapsedMilliseconds * 2 > t2.ElapsedMilliseconds);
        }
コード例 #4
0
        public async Task TestTaskV2Delay()
        {
            var t1        = Stopwatch.StartNew();
            var t2        = StopwatchV2.StartNewV2("TestTaskV2Delay");
            var min       = 0;
            var delayInMs = 100;

            for (int i = 0; i < 5; i++)
            {
                min += delayInMs;
                await TaskV2.Delay(delayInMs);

                Assert.InRange(t1.ElapsedMilliseconds, min * 0.05f, (min + delayInMs) * 5f);
                Assert.InRange(t2.ElapsedMilliseconds, min * 0.05f, (min + delayInMs) * 5f);
            }
        }