Skip to content

Commit 16ccbef

Browse files
--no-edit
1 parent 10a809d commit 16ccbef

3 files changed

Lines changed: 27 additions & 50 deletions

File tree

client-sdk-rust

src/data_track_stream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void DataTrackStream::onFfiEvent(const FfiEvent& event) {
114114
pushFrame(std::move(frame));
115115
} else if (dts.has_eos()) {
116116
std::optional<SubscribeDataTrackError> error;
117-
const auto &eos = dts.eos();
117+
const auto& eos = dts.eos();
118118
if (eos.has_error()) {
119119
error = SubscribeDataTrackError::fromProto(eos.error());
120120
}

src/tests/unit/test_data_track_stream.cpp

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
#include <gtest/gtest.h>
1818
#include <livekit/data_track_stream.h>
1919

20-
#include "data_track.pb.h"
21-
#include "ffi.pb.h"
22-
2320
#include <memory>
2421
#include <optional>
2522

23+
#include "data_track.pb.h"
24+
#include "ffi.pb.h"
25+
2626
namespace livekit {
2727

2828
class DataTrackStreamTest : public ::testing::Test {
@@ -31,19 +31,16 @@ class DataTrackStreamTest : public ::testing::Test {
3131
return std::unique_ptr<DataTrackStream>(new DataTrackStream());
3232
}
3333

34-
static void pushEvent(DataTrackStream &stream, const proto::FfiEvent &event) {
35-
stream.onFfiEvent(event);
36-
}
34+
static void pushEvent(DataTrackStream& stream, const proto::FfiEvent& event) { stream.onFfiEvent(event); }
3735

38-
static proto::FfiEvent makeEosEvent(
39-
std::optional<proto::SubscribeDataTrackErrorCode> code = std::nullopt,
40-
const std::string &message = {}) {
36+
static proto::FfiEvent makeEosEvent(std::optional<proto::SubscribeDataTrackErrorCode> code = std::nullopt,
37+
const std::string& message = {}) {
4138
proto::FfiEvent event;
42-
auto *stream_event = event.mutable_data_track_stream_event();
39+
auto* stream_event = event.mutable_data_track_stream_event();
4340
stream_event->set_stream_handle(0);
44-
auto *eos = stream_event->mutable_eos();
41+
auto* eos = stream_event->mutable_eos();
4542
if (code.has_value()) {
46-
auto *error = eos->mutable_error();
43+
auto* error = eos->mutable_error();
4744
error->set_code(code.value());
4845
error->set_message(message);
4946
}
@@ -56,9 +53,8 @@ class DataTrackStreamTest : public ::testing::Test {
5653
return event;
5754
}
5855

59-
static void expectTerminalError(const DataTrackStream &stream,
60-
SubscribeDataTrackErrorCode expected_code,
61-
const std::string &expected_message) {
56+
static void expectTerminalError(const DataTrackStream& stream, SubscribeDataTrackErrorCode expected_code,
57+
const std::string& expected_message) {
6258
const auto error = stream.terminalError();
6359
ASSERT_TRUE(error.has_value());
6460
EXPECT_EQ(error->code, expected_code);
@@ -77,9 +73,8 @@ TEST_F(DataTrackStreamTest, TerminalErrorEmptyForNormalEos) {
7773

7874
TEST_F(DataTrackStreamTest, TerminalErrorStoredForSubscribeFailureEos) {
7975
auto stream = makeStream();
80-
pushEvent(*stream,
81-
makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_UNPUBLISHED,
82-
"track unpublished before subscription completed"));
76+
pushEvent(*stream, makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_UNPUBLISHED,
77+
"track unpublished before subscription completed"));
8378

8479
DataTrackFrame frame;
8580
EXPECT_FALSE(stream->read(frame));
@@ -95,8 +90,7 @@ TEST_F(DataTrackStreamTest, CloseBeforeEosSuppressesLaterTerminalError) {
9590
stream->close();
9691

9792
pushEvent(*stream,
98-
makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_DISCONNECTED,
99-
"disconnected after local close"));
93+
makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_DISCONNECTED, "disconnected after local close"));
10094

10195
DataTrackFrame frame;
10296
EXPECT_FALSE(stream->read(frame));
@@ -105,37 +99,27 @@ TEST_F(DataTrackStreamTest, CloseBeforeEosSuppressesLaterTerminalError) {
10599

106100
TEST_F(DataTrackStreamTest, CloseAfterEosPreservesTerminalError) {
107101
auto stream = makeStream();
108-
pushEvent(*stream,
109-
makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_TIMEOUT,
110-
"subscription timed out"));
102+
pushEvent(*stream, makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_TIMEOUT, "subscription timed out"));
111103

112104
stream->close();
113105

114106
DataTrackFrame frame;
115107
EXPECT_FALSE(stream->read(frame));
116-
expectTerminalError(*stream, SubscribeDataTrackErrorCode::TIMEOUT,
117-
"subscription timed out");
108+
expectTerminalError(*stream, SubscribeDataTrackErrorCode::TIMEOUT, "subscription timed out");
118109
}
119110

120111
TEST_F(DataTrackStreamTest, DuplicateEosKeepsFirstTerminalError) {
121112
auto stream = makeStream();
122-
pushEvent(*stream,
123-
makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_UNPUBLISHED,
124-
"first terminal error"));
125-
pushEvent(*stream,
126-
makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_TIMEOUT,
127-
"second terminal error"));
113+
pushEvent(*stream, makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_UNPUBLISHED, "first terminal error"));
114+
pushEvent(*stream, makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_TIMEOUT, "second terminal error"));
128115

129-
expectTerminalError(*stream, SubscribeDataTrackErrorCode::UNPUBLISHED,
130-
"first terminal error");
116+
expectTerminalError(*stream, SubscribeDataTrackErrorCode::UNPUBLISHED, "first terminal error");
131117
}
132118

133119
TEST_F(DataTrackStreamTest, DuplicateEosDoesNotReplaceNormalEndWithError) {
134120
auto stream = makeStream();
135121
pushEvent(*stream, makeEosEvent());
136-
pushEvent(*stream,
137-
makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_INTERNAL,
138-
"late terminal error"));
122+
pushEvent(*stream, makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_INTERNAL, "late terminal error"));
139123

140124
DataTrackFrame frame;
141125
EXPECT_FALSE(stream->read(frame));
@@ -144,16 +128,11 @@ TEST_F(DataTrackStreamTest, DuplicateEosDoesNotReplaceNormalEndWithError) {
144128

145129
TEST_F(DataTrackStreamTest, EventsAfterCloseDoNotReplaceExistingTerminalError) {
146130
auto stream = makeStream();
147-
pushEvent(*stream,
148-
makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_PROTOCOL_ERROR,
149-
"protocol error"));
131+
pushEvent(*stream, makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_PROTOCOL_ERROR, "protocol error"));
150132
stream->close();
151-
pushEvent(*stream,
152-
makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_INTERNAL,
153-
"late error after close"));
133+
pushEvent(*stream, makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_INTERNAL, "late error after close"));
154134

155-
expectTerminalError(*stream, SubscribeDataTrackErrorCode::PROTOCOL_ERROR,
156-
"protocol error");
135+
expectTerminalError(*stream, SubscribeDataTrackErrorCode::PROTOCOL_ERROR, "protocol error");
157136
}
158137

159138
TEST_F(DataTrackStreamTest, NonDataTrackEventsAreIgnored) {
@@ -163,11 +142,9 @@ TEST_F(DataTrackStreamTest, NonDataTrackEventsAreIgnored) {
163142
EXPECT_FALSE(stream->terminalError().has_value());
164143

165144
pushEvent(*stream,
166-
makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_TIMEOUT,
167-
"still accepts later data track eos"));
145+
makeEosEvent(proto::SUBSCRIBE_DATA_TRACK_ERROR_CODE_TIMEOUT, "still accepts later data track eos"));
168146

169-
expectTerminalError(*stream, SubscribeDataTrackErrorCode::TIMEOUT,
170-
"still accepts later data track eos");
147+
expectTerminalError(*stream, SubscribeDataTrackErrorCode::TIMEOUT, "still accepts later data track eos");
171148
}
172149

173150
} // namespace livekit

0 commit comments

Comments
 (0)