Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add async version of IRestChannel.Status #1264

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/IO.Ably.Shared/Rest/IRestChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public interface IRestChannel
/// Returns the active status for the channel including the number of publishers, subscribers and presenceMembers etc.
/// </summary>
/// <returns><see cref="ChannelDetails"/>Channel Details.</returns>
Task<ChannelDetails> StatusAsync();

/// <summary>
/// Sync version of <see cref="StatusAsync()"/>.
/// /// Prefer async version where possible.
/// </summary>
/// <returns><see cref="ChannelDetails"/>Channel Details.</returns>
ChannelDetails Status();
}

Expand Down
3 changes: 2 additions & 1 deletion src/IO.Ably.Shared/Rest/RestChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public PaginatedResult<Message> History(PaginatedRequestParams query)
return AsyncHelper.RunSync(() => HistoryAsync(query));
}

private async Task<ChannelDetails> StatusAsync()
/// <inheritdoc/>
public async Task<ChannelDetails> StatusAsync()
{
AblyRequest request = _ablyRest.CreateGetRequest("/channels/" + Name);
return await _ablyRest.ExecuteRequest<ChannelDetails>(request);
Expand Down
49 changes: 49 additions & 0 deletions src/IO.Ably.Tests.Shared/Rest/ChannelSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,55 @@ public ChannelPublish(ITestOutputHelper output)
}
}

public class ChannelStatus : ChannelSpecs
{
public ChannelStatus(ITestOutputHelper output)
: base(output)
{
}

[Fact]
[Trait("spec", "XXX")]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what value I should have here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check if we have existing tests for channel.Status and add this test side by side?

Copy link
Collaborator

@sacOO7 sacOO7 Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public async Task Status_ShouldMakeGetRequest()
{
const string channelName = "test:one";
var response = new ChannelDetails
{
ChannelId = "foo",
Status = new Ably.Rest.ChannelStatus
{
IsActive = true,
Occupancy = new ChannelOccupancy
{
Metrics = new ChannelMetrics
{
Connections = 1,
Publishers = 2,
Subscribers = 3,
PresenceConnections = 4,
PresenceSubscribers = 5,
PresenceMembers = 6,
},
},
},
};
var client = GetRestClient(request => new AblyResponse
{
Headers = DataRequestQueryTests.GetSampleHistoryRequestHeaders(),
TextResponse = response.ToJson(),
}.ToTask());

var channel = client.Channels.Get(channelName);
var result = await channel.StatusAsync();
LastRequest.Method.Should().Be(HttpMethod.Get);
LastRequest.Url.Should().Be($"/channels/{channelName}");
result.Status.Occupancy.Metrics.PresenceMembers.Should().Be(6);

var syncResult = channel.Status();
syncResult.Should().BeEquivalentTo(result);
}
}

public class ChannelHistory : ChannelSpecs
{
private readonly IRestChannel _channel;
Expand Down
Loading