mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-13 22:40:01 -04:00
add new unit test, fix minor bugs
This commit is contained in:
parent
f8e55ea307
commit
1730e6d964
7 changed files with 30 additions and 2 deletions
|
@ -119,7 +119,7 @@ class HTTPSession extends CurlSession {
|
||||||
|
|
||||||
static async create_options(params) {
|
static async create_options(params) {
|
||||||
let body = null;
|
let body = null;
|
||||||
let request_obj = new Request("/", params);
|
let request_obj = new Request("http://127.0.0.1/", params);
|
||||||
let array_buffer = await request_obj.arrayBuffer();
|
let array_buffer = await request_obj.arrayBuffer();
|
||||||
if (array_buffer.byteLength > 0) {
|
if (array_buffer.byteLength > 0) {
|
||||||
body = new Uint8Array(array_buffer);
|
body = new Uint8Array(array_buffer);
|
||||||
|
|
|
@ -49,4 +49,5 @@ void session_remove_request(struct SessionInfo *session, CURL* http_handle) {
|
||||||
|
|
||||||
void session_cleanup(struct SessionInfo *session) {
|
void session_cleanup(struct SessionInfo *session) {
|
||||||
curl_multi_cleanup(session->multi_handle);
|
curl_multi_cleanup(session->multi_handle);
|
||||||
|
free(session);
|
||||||
}
|
}
|
|
@ -52,5 +52,8 @@ class JSTest(unittest.TestCase):
|
||||||
def test_tls_socket(self):
|
def test_tls_socket(self):
|
||||||
self.run_test("test_tls_socket.js")
|
self.run_test("test_tls_socket.js")
|
||||||
|
|
||||||
|
def test_http_session(self):
|
||||||
|
self.run_test("test_http_session.js")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
|
@ -3,5 +3,6 @@ async function test() {
|
||||||
for (let i=0; i<20; i++) {
|
for (let i=0; i<20; i++) {
|
||||||
let r = await libcurl.fetch("https://example.com/");
|
let r = await libcurl.fetch("https://example.com/");
|
||||||
assert(r.status === 200, "wrong status");
|
assert(r.status === 200, "wrong status");
|
||||||
|
await r.text();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
async function test() {
|
async function test() {
|
||||||
let r = await libcurl.fetch("https://example.com/");
|
let r = await libcurl.fetch("https://example.com/");
|
||||||
assert(r.status === 200, "wrong status");
|
assert(r.status === 200, "wrong status");
|
||||||
|
await r.text();
|
||||||
}
|
}
|
|
@ -2,7 +2,10 @@ async function test() {
|
||||||
await libcurl.fetch("https://www.example.com/");
|
await libcurl.fetch("https://www.example.com/");
|
||||||
let promises = [];
|
let promises = [];
|
||||||
for (let i=0; i<10; i++) {
|
for (let i=0; i<10; i++) {
|
||||||
promises.push(libcurl.fetch("https://www.example.com/"))
|
promises.push((async ()=>{
|
||||||
|
let r = await libcurl.fetch("https://www.example.com/");
|
||||||
|
await r.text();
|
||||||
|
})())
|
||||||
}
|
}
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
19
client/tests/scripts/test_http_session.js
Normal file
19
client/tests/scripts/test_http_session.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
async function test() {
|
||||||
|
let sessions = [];
|
||||||
|
for (let i=0; i<5; i++) {
|
||||||
|
sessions.push(new libcurl.HTTPSession());
|
||||||
|
}
|
||||||
|
|
||||||
|
let promises = [];
|
||||||
|
for (let session of sessions) {
|
||||||
|
promises.push((async ()=>{
|
||||||
|
let r = await session.fetch("https://www.example.com/");
|
||||||
|
await r.text();
|
||||||
|
})());
|
||||||
|
}
|
||||||
|
await Promise.all(promises);
|
||||||
|
|
||||||
|
for (let session of sessions) {
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue