public async Task TestChannelsAsync() { const string topicName = "/my_test_topic_xyz"; await using var client = await RosClient.CreateAsync(MasterUri, CallerId, CallerUri); await using var publisher = await RosChannelWriterUtils.CreateWriterAsync <String>(client, topicName); publisher.LatchingEnabled = true; var systemState = await client.GetSystemStateAsync(); Assert.True( systemState.Publishers.Any(tuple => tuple.Topic == topicName && tuple.Members.Contains(CallerId))); const string msgText = "test message"; publisher.Write(new String(msgText)); await using var subscriber = await RosChannelReaderUtils.CreateReaderAsync <String>(client, topicName); using var source = new CancellationTokenSource(5000); await foreach (var msg in subscriber.ReadAllAsync(source.Token)) { if (msg.Data == msgText) { break; } } }
public async Task TestGenericChannelReaderAsync() { const string topicName = "/my_test_topic_xyz_a"; await using var client = await RosClient.CreateAsync(MasterUri, CallerId, CallerUri); await using var publisher = await RosChannelWriterUtils.CreateWriterAsync <String>(client, topicName); publisher.LatchingEnabled = true; var systemState = await client.GetSystemStateAsync(); Assert.True( systemState.Publishers.Any(tuple => tuple.Topic == topicName && tuple.Members.Contains(CallerId))); const string msgText = "test message"; publisher.Write(new String(msgText)); // reader has no message type, it will use whatever the publisher sends during handshake await using var subscriber = await client.CreateReaderAsync(topicName); using var source = new CancellationTokenSource(5000); await foreach (var msg in subscriber.ReadAllAsync(source.Token)) { if (msg is String { Data: msgText })