schulz3000 / deepstreamNet

dotnet Client for deepstream.io
MIT License
38 stars 9 forks source link

Intermittent error on data provider #23

Closed grendo closed 7 years ago

grendo commented 7 years ago

Hi, great work on the .net client. Most things seem to be working well. This might not be anything to do with the client but I have this test for creating a data provider. When I run in a sweet of tests it hangs consistently unless I have the 300ms sleep in the test. By itself it seems to be ok. Do you think we need a whenReady method on the record similar to the js client so we can be sure deepstream has done all its things ?

The error on the deepstream console is INVALID_MESSAGE | RLAtest/datap/*test/datap/blah

    [Test]
    public async Task TestDataProvider()
    {
        var val = Guid.NewGuid().ToString();
        var tcs = new TaskCompletionSource<string>();
        var c1 = await GetConnection("admin", "test");
        var c = await GetConnection("admin", "test");
        await c.Records.ListenAsync("test/datap/*", async (match, isSubscribed, resposne) =>
        {

            var rec = await c.Records.GetRecordAsync(match);
            var obj = new JObject();
            obj["data"] = val;
            bool result = await c.Records.SetWithAckAsync(rec, obj);
            await c.Records.DiscardAsync(rec);
            if (result)
            {
                resposne.Accept();
            }
            else
            {
                resposne.Reject();
            }
            tcs.SetResult("done");
        });
        var recsub = await c1.Records.GetRecordAsync("test/datap/blah");
        await tcs.Task;

        // some sort of timing issue, without the sleep here the test hangs when run in a sweet of tests
        // without the sleep I get INVALID_MESSAGE | RLAtest/datap/*test/datap/blah
        // on the deepstream sys out seems to have a funny character which shows up asa box with a question mark
        System.Threading.Thread.Sleep(300);

        // should not have to do this but record is not getting the updates data from the data provider
        // so discard the record and get a snapshot to prove the data was saved
        // may be related to the property change event not firing
        // there is an issue raised on github to fix this
        await c1.Records.DiscardAsync(recsub);
        var snapShot = await c1.Records.SnapshotAsync("test/datap/blah");
        var updatedVal = snapShot["data"];
        Assert.AreEqual(val, updatedVal.ToString());

        c1.Dispose();
        c.Dispose();

    }
schulz3000 commented 7 years ago

not reproduceable with latest version of deepstreamNet and deepstream.io 3.0.0 for me