mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
SRS5: API: Fix duplicated on_stop callback event bug. v5.0.125 (#3349)
* fix hls bug:Duplicated on_stop callback
* improve utest
* Refine magic number.
* API: Fix duplicated on_stop callback event bug. v5.0.125
Co-authored-by: winlin <winlin@vip.126.com>
PICK 3727d0527c
This commit is contained in:
parent
e4e87c0403
commit
57cc843000
6 changed files with 40 additions and 12 deletions
|
@ -144,6 +144,18 @@ string mock_http_response3(int status, string content)
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
string mock_http_response4(int status, string content)
|
||||
{
|
||||
string m3u8_header = "#EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=1,AVERAGE-BANDWIDTH=1\n";
|
||||
|
||||
stringstream ss;
|
||||
ss << "HTTP/1.1 " << status << " " << srs_generate_http_status_text(status) << "\r\n"
|
||||
<< "Content-Length: " << content.length() + m3u8_header.length() << "\r\n\r\n"
|
||||
<< m3u8_header
|
||||
<< content;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool is_string_contain(string substr, string str)
|
||||
{
|
||||
return (string::npos != str.find(substr));
|
||||
|
@ -1286,7 +1298,11 @@ VOID TEST(ProtocolHTTPTest, VodStreamHandlers)
|
|||
HELPER_ASSERT_SUCCESS(r.set_url("/index.m3u8?hls_ctx=123456", false));
|
||||
|
||||
HELPER_ASSERT_SUCCESS(h.serve_http(&w, &r));
|
||||
__MOCK_HTTP_EXPECT_STREQ(200, "Hello, world!", w);
|
||||
__MOCK_HTTP_EXPECT_STREQ4(200, "/index.m3u8?hls_ctx=123456", w);
|
||||
|
||||
MockResponseWriter w2;
|
||||
HELPER_ASSERT_SUCCESS(h.serve_http(&w2, &r));
|
||||
__MOCK_HTTP_EXPECT_STREQ(200, "Hello, world!", w2);
|
||||
}
|
||||
|
||||
// Should return "hls_ctx"
|
||||
|
@ -1304,7 +1320,11 @@ VOID TEST(ProtocolHTTPTest, VodStreamHandlers)
|
|||
HELPER_ASSERT_SUCCESS(r.set_url("/index.m3u8?hls_ctx=123456", false));
|
||||
|
||||
HELPER_ASSERT_SUCCESS(h.serve_http(&w, &r));
|
||||
__MOCK_HTTP_EXPECT_STREQ(200, "livestream-13.ts?hls_ctx=123456", w);
|
||||
__MOCK_HTTP_EXPECT_STREQ4(200, "/index.m3u8?hls_ctx=123456", w);
|
||||
|
||||
MockResponseWriter w2;
|
||||
HELPER_ASSERT_SUCCESS(h.serve_http(&w2, &r));
|
||||
__MOCK_HTTP_EXPECT_STREQ(200, "livestream-13.ts?hls_ctx=123456", w2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ public:
|
|||
|
||||
string mock_http_response(int status, string content);
|
||||
string mock_http_response2(int status, string content);
|
||||
string mock_http_response4(int status, string content);
|
||||
bool is_string_contain(string substr, string str);
|
||||
|
||||
#define __MOCK_HTTP_EXPECT_STREQ(status, text, w) \
|
||||
|
@ -59,6 +60,9 @@ bool is_string_contain(string substr, string str);
|
|||
#define __MOCK_HTTP_EXPECT_STREQ2(status, text, w) \
|
||||
EXPECT_STREQ(mock_http_response2(status, text).c_str(), HELPER_BUFFER2STR(&w.io.out_buffer).c_str())
|
||||
|
||||
#define __MOCK_HTTP_EXPECT_STREQ4(status, text, w) \
|
||||
EXPECT_STREQ(mock_http_response4(status, text).c_str(), HELPER_BUFFER2STR(&w.io.out_buffer).c_str())
|
||||
|
||||
#define __MOCK_HTTP_EXPECT_STRHAS(status, text, w) \
|
||||
EXPECT_PRED2(is_string_contain, text, HELPER_BUFFER2STR(&w.io.out_buffer).c_str())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue