Skip to content

Commit

Permalink
Get Windows tests working & passing. (#560)
Browse files Browse the repository at this point in the history
I added an appveyor.yml. This should mean I no longer have to configure appveyor in the web UI. And more of the test is set up automatically, without awkward scripting in various convoluted languages.

But it also gave me the opportunity to get the tests running on Windows. And guess what? They didn't all pass! The test for asynchronous connection (using pqxx::connecting) would hang. Turns out it was completely unnecessary for libpqxx to manage blocking/nonblocking mode on the socket. So that's fixed now.
  • Loading branch information
jtv authored Apr 10, 2022
1 parent 69a5d93 commit 12f26bf
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- Deprecate `exec` functions' `desc` parameter.
- Fix `placeholders` documentation. (#557)
- Strip `const` and references from `value_type`. (#558)
- Get tests running on appveyor. (#560)
- Fix broken nonblocking connection on Windows. (#560)
7.7.2
- Fix up damage done by auto-formatting.
7.7.1
Expand Down
28 changes: 28 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 1.0.{build}
image: Visual Studio 2022
services: postgresql12
before_build:
- cmd: >-
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
cmake -DBUILD_SHARED_LIBS=1 -DCMAKE_CXX_STANDARD=23
configuration: Release
build:
parallel: true
project: libpqxx.sln
test_script:
- ps: >-
$env:Path += ";.\src\Release;C:\Program Files\PostgreSQL\12\bin"
$env:PGUSER = "postgres"
$env:PGPASSWORD = "Password12!"
.\test\Release\runner.exe
notifications:
- provider: Email
subject: 'libpqxx: AppVeyor build failure'
message: The libpqxx AppVeyor build has failed.
on_build_success: false
on_build_failure: true
on_build_status_changed: false
4 changes: 4 additions & 0 deletions include/pqxx/connection.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,10 @@ public:

#if defined(_WIN32) || __has_include(<fcntl.h>)
/// Set socket to blocking (true) or nonblocking (false).
/** @warning Do not use this unless you _really_ know what you're doing.
* @warning This function is available on most systems, but not necessarily
* all.
*/
void set_blocking(bool block) &;
#endif // defined(_WIN32) || __has_include(<fcntl.h>)

Expand Down
6 changes: 4 additions & 2 deletions src/connection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ pqxx::connection::connection(
{
if (m_conn == nullptr)
throw std::bad_alloc{};
if (status() == CONNECTION_BAD)
throw pqxx::broken_connection{PQerrorMessage(m_conn)};
}


Expand Down Expand Up @@ -138,6 +140,7 @@ void pqxx::connection::complete_init()
catch (std::exception const &)
{
PQfinish(m_conn);
m_conn = nullptr;
throw;
}
}
Expand Down Expand Up @@ -479,6 +482,7 @@ void PQXX_COLD pqxx::connection::cancel_query()

namespace
{
// C++20: std::span?
/// Get error string for a given @c errno value.
template<std::size_t BYTES>
char const *PQXX_COLD
Expand Down Expand Up @@ -1245,7 +1249,6 @@ std::string pqxx::connection::connection_string() const
pqxx::connecting::connecting(zview connection_string) :
m_conn{connection::connect_nonblocking, connection_string}
{
m_conn.set_blocking(false);
}
#endif // defined(_WIN32) || __has_include(<fcntl.h>

Expand All @@ -1266,7 +1269,6 @@ pqxx::connection pqxx::connecting::produce() &&
if (!done())
throw usage_error{
"Tried to produce a nonblocking connection before it was done."};
m_conn.set_blocking(true);
m_conn.complete_init();
return std::move(m_conn);
}
Expand Down
2 changes: 1 addition & 1 deletion src/wait.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void pqxx::internal::wait_fd(
short const events{static_cast<short>(
(for_read ? POLLRDNORM : 0) | (for_write ? POLLWRNORM : 0))};
WSAPOLLFD fdarray{SOCKET(fd), events, 0};
WSAPoll(&fdarray, 1, to_milli<unsigned>(seconds, microseconds));
WSAPoll(&fdarray, 1u, to_milli<unsigned>(seconds, microseconds));
// TODO: Check for errors.
#elif defined(PQXX_HAVE_POLL)
auto const events{static_cast<short>(
Expand Down
1 change: 0 additions & 1 deletion test/unit/test_nonblocking_connect.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <pqxx/connection>
#include <pqxx/transaction>

#include <pqxx/internal/wait.hxx>
Expand Down

0 comments on commit 12f26bf

Please sign in to comment.