zombiezen / postgrestest

A Go test harness that starts an ephemeral PostgreSQL server
Apache License 2.0
41 stars 3 forks source link

feature request: deterministic DSN #3

Open stapelberg opened 3 months ago

stapelberg commented 3 months ago

Hello again @zombiezen; I have another request but figured I’d file it separately from issue #2 so that you can consider them separately.

Currently, postgrestest sets a random password and creates a database with random name. This is great for isolation, but also means that passing a PostgreSQL environment URL to a whole bunch of tests via an environment variable will necessarily invalidate Go’s cache (because the environment variable contains different passwords and database names from invocation to invocation).

This can be fixed by making PostgreSQL listen on a UNIX domain socket instead of a TCP port, which obviates the need for a password. The database name can be hard-coded to “test”, as we’re working with ephemeral instances anyway that don’t contain any other tables.

Would this be a change for which you’d accept contributions? I have a proof-of-concept working, but will only invest time in cleaning it up if you’re interested in the change :)

Thanks

zombiezen commented 3 months ago

I'm not opposed in principle, but I have a hazy recollection of trying to use UNIX domain sockets in early drafts of this package (might never have left proof of concept, I don't see it in version history) and running into trouble. The best evidence I can come up with for this hunch is go.dev/issue/30844 and https://github.com/lib/pq/issues/796, but in re-reading now, I don't see anything stopping it.

Regardless, I think we will need to support TCP at least for Windows. Basically, as long as you have something that passes in CI, I would accept it. 👍

stapelberg commented 3 months ago

Good to know! Yeah, I figured that using TCP ports might be for Windows.

However, I have since seen that Go builds the unixsock_posix.go variant on Windows, too: https://cs.opensource.google/go/go/+/refs/tags/go1.22.1:src/net/unixsock_posix.go;l=5;drc=a81507868344dccebef13c6d8d890633e59a93e3 and there was a blog post by Microsoft from 2017 explaining that UNIX domain sockets now work on Windows, too: https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/

I’ll try to find some time to boot up a Windows instance and test it out. Maybe we can use UNIX Domain Sockets everywhere, perhaps with a fallback for (older?) Windows if needed.