vlingo-net / xoom-net-common

These are just a few common tools shared across various vlingo .NET projects.
Mozilla Public License 2.0
7 stars 9 forks source link

When With() called on ICompletes server end than the client can't chain continuation #55

Open tjaskula opened 4 years ago

tjaskula commented 4 years ago

This can be demonstrated with the following test

[Fact]
        public void TestOnClientAndServerSetupWhenServerIsFaster()
        {
            var ints = new List<int>();
            var completeInteger = NewEmptyCompletes<int>();
            var expected = Enumerable.Range(0, 1000).ToList();

            var server = new Thread(() => expected.ForEach(i => completeInteger.With(i)));
            var client = new Thread(() => completeInteger.AndThen(i =>
            {
                ints.Add(i);
                return i;
            }).Repeat());

            server.Start();
            Thread.Sleep(10);
            client.Start();

            server.Join();
            client.Join();

            var intHashSet = new HashSet<int>(ints);
            var expectedHashSet = new HashSet<int>(expected);

            expectedHashSet.RemoveWhere(h => intHashSet.Contains(h));
            Assert.Empty(expectedHashSet);
        }

As you can see client is late by 10ms with processing. Attaching a continuation is too late because the server has already processed the continuation on its end.

On the JVM this is supported by the SinkAndSourceBasedCompletes but needs to be run agains the regular implementation of BasicCompletes in order to confirm that both has the same behavior.