summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeffrey Tolar <tolar@yahooinc.com>2021-09-18 11:29:44 -0500
committerDaniel Stenberg <daniel@haxx.se>2021-10-06 14:38:59 +0200
commit5f563495f1f9cf7ef4f23f997e4c2707dd3e74a8 (patch)
treee6d017874795f4c0bfe61105b1a245f44699ae2c /tests
parent013cb2ff7d3a37cab6910cc2e4d255377d341b6e (diff)
downloadcurl-5f563495f1f9cf7ef4f23f997e4c2707dd3e74a8.tar.gz
CURLOPT_MAXLIFETIME_CONN: maximum allowed lifetime for conn reuse
... and close connections that are too old instead of reusing them. By default, this behavior is disabled. Bug: https://curl.se/mail/lib-2021-09/0058.html Closes #7751
Diffstat (limited to 'tests')
-rw-r--r--tests/data/Makefile.inc2
-rw-r--r--tests/data/test154267
-rw-r--r--tests/libtest/Makefile.inc6
-rw-r--r--tests/libtest/lib1542.c86
4 files changed, 159 insertions, 2 deletions
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
index 41249fdad..57f2abf69 100644
--- a/tests/data/Makefile.inc
+++ b/tests/data/Makefile.inc
@@ -189,7 +189,7 @@ test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1515 \
test1516 test1517 test1518 test1519 test1520 test1521 test1522 test1523 \
test1524 test1525 test1526 test1527 test1528 test1529 test1530 test1531 \
test1532 test1533 test1534 test1535 test1536 test1537 test1538 test1539 \
-test1540 \
+test1540 test1542 \
\
test1550 test1551 test1552 test1553 test1554 test1555 test1556 test1557 \
test1558 test1559 test1560 test1561 test1562 test1563 test1564 test1565 \
diff --git a/tests/data/test1542 b/tests/data/test1542
new file mode 100644
index 000000000..6a9b7f0b7
--- /dev/null
+++ b/tests/data/test1542
@@ -0,0 +1,67 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+connection re-use
+persistent connection
+CURLOPT_MAXLIFETIME_CONN
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data nocheck="yes">
+HTTP/1.1 200 OK
+Content-Length: 0
+
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+<tool>
+lib%TESTNUMBER
+</tool>
+ <name>
+connection reuse with CURLOPT_MAXLIFETIME_CONN
+ </name>
+ <command>
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+GET /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+GET /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+GET /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+GET /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+</protocol>
+<file name="log/stderr%TESTNUMBER" mode="text">
+== Info: Connection #0 to host %HOSTIP left intact
+== Info: Connection #0 to host %HOSTIP left intact
+== Info: Connection #0 to host %HOSTIP left intact
+== Info: Closing connection 0
+== Info: Connection #1 to host %HOSTIP left intact
+</file>
+<stripfile>
+$_ = '' if (($_ !~ /left intact/) && ($_ !~ /Closing connection/))
+</stripfile>
+</verify>
+</testcase>
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
index 0f70ceb4b..ade101290 100644
--- a/tests/libtest/Makefile.inc
+++ b/tests/libtest/Makefile.inc
@@ -55,7 +55,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \
lib1518 lib1520 lib1521 lib1522 lib1523 \
lib1525 lib1526 lib1527 lib1528 lib1529 lib1530 lib1531 lib1532 lib1533 \
lib1534 lib1535 lib1536 lib1537 lib1538 lib1539 \
- lib1540 \
+ lib1540 lib1542 \
lib1550 lib1551 lib1552 lib1553 lib1554 lib1555 lib1556 lib1557 \
lib1558 lib1559 lib1560 lib1564 lib1565 lib1567 lib1568 lib1569 \
lib1591 lib1592 lib1593 lib1594 lib1596 \
@@ -569,6 +569,10 @@ lib1540_SOURCES = lib1540.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1540_LDADD = $(TESTUTIL_LIBS)
lib1540_CPPFLAGS = $(AM_CPPFLAGS)
+lib1542_SOURCES = lib1542.c $(SUPPORTFILES) $(TESTUTIL) $(TSTTRACE) $(WARNLESS)
+lib1542_LDADD = $(TESTUTIL_LIBS)
+lib1542_CPPFLAGS = $(AM_CPPFLAGS)
+
lib1550_SOURCES = lib1550.c $(SUPPORTFILES)
lib1550_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1517
diff --git a/tests/libtest/lib1542.c b/tests/libtest/lib1542.c
new file mode 100644
index 000000000..4e17d9d36
--- /dev/null
+++ b/tests/libtest/lib1542.c
@@ -0,0 +1,86 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+/*
+ * Test CURLOPT_MAXLIFETIME_CONN:
+ * Send four requests, sleeping between the second and third and setting
+ * MAXLIFETIME_CONN between the third and fourth. The first three requests
+ * should use the same connection, and the fourth request should close the
+ * first connection and open a second.
+ */
+
+#include "test.h"
+#include "testutil.h"
+#include "testtrace.h"
+#include "warnless.h"
+#include "memdebug.h"
+
+#if defined(WIN32) || defined(_WIN32)
+#define sleep(sec) Sleep ((sec)*1000)
+#endif
+
+int test(char *URL)
+{
+ CURL *easy = NULL;
+ int res = 0;
+
+ global_init(CURL_GLOBAL_ALL);
+
+ res_easy_init(easy);
+
+ easy_setopt(easy, CURLOPT_URL, URL);
+
+ libtest_debug_config.nohex = 1;
+ libtest_debug_config.tracetime = 0;
+ easy_setopt(easy, CURLOPT_DEBUGDATA, &libtest_debug_config);
+ easy_setopt(easy, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
+ easy_setopt(easy, CURLOPT_VERBOSE, 1L);
+
+ res = curl_easy_perform(easy);
+ if(res)
+ goto test_cleanup;
+
+ res = curl_easy_perform(easy);
+ if(res)
+ goto test_cleanup;
+
+ /* CURLOPT_MAXLIFETIME_CONN is inclusive - the connection needs to be 2
+ * seconds old */
+ sleep(2);
+
+ res = curl_easy_perform(easy);
+ if(res)
+ goto test_cleanup;
+
+ easy_setopt(easy, CURLOPT_MAXLIFETIME_CONN, 1L);
+
+ res = curl_easy_perform(easy);
+ if(res)
+ goto test_cleanup;
+
+test_cleanup:
+
+ curl_easy_cleanup(easy);
+ curl_global_cleanup();
+
+ return (int)res;
+}