예제 #1
0
#pragma warning disable xUnit1013
        public new void Dispose()
        {
            context.Stop();
            context.WaitForStopped();
            context.Poll();
            base.Dispose();
        }
예제 #2
0
        public void Poll()
        {
            MOCK_ContextPoll((IntPtr context, ref int count) =>
            {
                Assert.Equal(pointer, context);
                count = 5;
                return((int)Yogi.ErrorCode.Ok);
            });

            Assert.Equal(5, context.Poll());
        }
        public void AwaitSignal()
        {
            var sigset = new Yogi.SignalSet(context, Yogi.Signals.Term | Yogi.Signals.Usr5);

            bool called = false;

            sigset.AwaitSignalAsync((res, signal) => {
                Assert.IsType <Yogi.Success>(res);
                Assert.Equal(Yogi.ErrorCode.Ok, res.ErrorCode);
                Assert.Equal(Yogi.Signals.Term, signal);
                called = true;
            });
            GC.Collect();
            Yogi.RaiseSignal(Yogi.Signals.Term, "123");
            GC.Collect();
            context.Poll();
            GC.Collect();
            Assert.True(called);

            called = false;
            sigset.AwaitSignalAsync <string>((res, signal, sigarg) => {
                Assert.IsType <Yogi.Success>(res);
                Assert.Equal(Yogi.ErrorCode.Ok, res.ErrorCode);
                Assert.Equal(Yogi.Signals.Term, signal);
                Assert.Null(sigarg);
                called = true;
            });
            Yogi.RaiseSignal(Yogi.Signals.Term);
            context.Poll();
            Assert.True(called);

            called = false;
            sigset.AwaitSignalAsync <string>((res, signal, sigarg) => {
                Assert.IsType <Yogi.Success>(res);
                Assert.Equal(Yogi.ErrorCode.Ok, res.ErrorCode);
                Assert.Equal(Yogi.Signals.Term, signal);
                Assert.Equal("Hello", sigarg);
                called = true;
            });
            Yogi.RaiseSignal(Yogi.Signals.Term, "Hello");
            context.Poll();
            Assert.True(called);
        }
예제 #4
0
        public void CancelAwaitEvent()
        {
            var branch = new Yogi.Branch(context, "{\"name\":\"My Branch\"}");

            bool called = false;

            branch.AwaitEventAsync(Yogi.BranchEvents.All, (res, ev, evres, info) =>
            {
                Assert.IsType <Yogi.Failure>(res);
                Assert.Equal(Yogi.ErrorCode.Canceled, res.ErrorCode);
                Assert.IsType <Yogi.BranchEvents>(ev);
                Assert.Equal(Yogi.BranchEvents.None, ev);
                Assert.IsType <Yogi.Success>(evres);
                Assert.Equal(Yogi.ErrorCode.Ok, evres.ErrorCode);
                Assert.Null(info);
                called = true;
            });

            branch.CancelAwaitEvent();
            context.Poll();
            Assert.True(called);

            GC.KeepAlive(branch);
        }
예제 #5
0
        public static void RunContextUntilBranchesAreConnected(Yogi.Context context,
                                                               params Yogi.Branch[] branches)
        {
            var uuids = new Dictionary <Yogi.Branch, List <Guid> >();

            foreach (var branch in branches)
            {
                uuids[branch] = new List <Guid>();
            }

            foreach (var entry in uuids)
            {
                foreach (var branch in branches)
                {
                    if (branch != entry.Key)
                    {
                        entry.Value.Add(branch.Uuid);
                    }
                }
            }

            var start = DateTime.Now;

            while (uuids.Count > 0)
            {
                context.Poll();

                var entry = uuids.First();
                var infos = entry.Key.GetConnectedBranches();
                foreach (var info in infos)
                {
                    var uuid = info.Key;
                    entry.Value.Remove(uuid);
                }

                if (entry.Value.Count == 0)
                {
                    uuids.Remove(entry.Key);
                }

                if (DateTime.Now - start > TimeSpan.FromSeconds(3))
                {
                    throw new Exception("Branches did not connect");
                }
            }
        }