Compze.DbPool.Service 0.16.0-alpha

Prefix Reserved
This is a prerelease version of Compze.DbPool.Service.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet tool install --global Compze.DbPool.Service --version 0.16.0-alpha
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local Compze.DbPool.Service --version 0.16.0-alpha
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=Compze.DbPool.Service&version=0.16.0-alpha&prerelease
                    
nuke :add-package Compze.DbPool.Service --version 0.16.0-alpha
                    

Compze.DbPool.Service

The DbPool service: one process on a trusted network that owns a PostgreSQL, a MySQL and a SQL Server instance, and lends their empty databases to the tests of every machine there, through Compze.DbPool's providers.

  • One service per instance: the service holds a lock on each instance, on a connection of its own, so a second service refuses to start, on whatever address it reaches the instance, and names the machine and process of the one that owns it. A service killed a moment ago holds its lock until its server notices, so a service that starts waits up to 10 seconds for the lock before it refuses.
  • Reservations in memory: a restarted service knows nothing of the reservations made before. It empties each database of its pool that it finds and lends it again, even one a test still holds: restart it when no tests run.
  • Ready databases: a returned database is emptied in the background, so the next test is lent one already empty.
  • Reservations end: a database whose reservation ends before its pool returns it is never lent again, and is dropped once nothing is connected to it.

Running it

dotnet tool install --global Compze.DbPool.Service --prerelease
compze-dbpool-service run

The first run writes a configuration file to fill in, %ProgramData%\Compze.DbPool.Service\configuration.json: the address of the machine the tests connect to, the port the service listens at, and the master connection string of each SQL instance. A change takes a restart. run --configuration <file> reads another file. A property the file doesn't know is refused, rather than ignored: PoolName, which version 0.1.0 read, and RegistryServerPort, which versions before 0.5.0 read for the port, too. Unless ListenOn is a loopback address, the service listens on every address of the machine, IPv6 and IPv4.

As a Windows service that starts with Windows: compze-dbpool-service install-windows-service [--configuration <file>], in an elevated prompt, with the configuration filled in. It registers the service, which reads that file each time it starts, and starts it; its log goes to service.log beside the configuration file. uninstall-windows-service stops it and removes the registration.

As a scheduled task that starts when you log on: compze-dbpool-service install-logon-task [--configuration <file>], in a prompt that needn't be elevated, with the configuration filled in. It registers a scheduled task named Compze.DbPool.Service that starts the service when you log on, as you, so a master connection string may use your Windows login (Integrated Security=True), and starts it. The service runs with no window, reading that file each time it starts, and its log goes to service.log beside the configuration file. Ending the task stops the service: Stop-ScheduledTask Compze.DbPool.Service, and Start-ScheduledTask Compze.DbPool.Service starts it again. uninstall-logon-task ends the task and removes it.

The task runs the service in a console host with no window of its own, conhost.exe --headless: a console program that a scheduled task runs directly gets a window, which a hidden window style only minimizes where Windows Terminal is the default terminal. Ending the task ends that console host, and the service, finding its console gone, stops.

Each master connection string's login must be allowed to create and drop databases. The tests connect with it too, so its host must be a name they can reach.

A PostgreSQL server on Windows wants lc_messages = 'C': otherwise each new connection's backend walks every Windows locale to resolve the locale's name, which took about a third of PostgreSQL's processor time in Compze's specifications. It changes only the language of the server's messages, and needs no restart:

ALTER SYSTEM SET lc_messages = 'C';
SELECT pg_reload_conf();

A test project names the service's machine and port, such as 192.168.0.11:7531, in its build property CompzeDbPoolService: see Compze.DbPool.ServiceClient's README. A test on the service's own machine finds it at port 7531 without it. The pools talk to the service over a TCP protocol of their own, which names its version in each request: a service serves the Compze.DbPool.ServiceClient of its own release, and refuses an older or newer one, saying so.

The service authenticates nobody and encrypts nothing, and its answers carry the SQL connection strings, credentials included. Run it only on a network where that is acceptable.

Running it as a child process of your own

A test run that starts its own SQL server can start its own DbPool service over it the same way, with nothing installed on the machine and no fixed port:

  1. Get the tool without installing it for the machine: a local tool manifest in your repository (dotnet new tool-manifest, then dotnet tool install Compze.DbPool.Service --prerelease, and dotnet tool restore where it runs), or dotnet tool install Compze.DbPool.Service --prerelease --tool-path <folder>.

  2. Write its configuration to a file of your own:

    {
      "ListenOn": "127.0.0.1",
      "Port": 0,
      "PostgreSql": "Host=localhost;Port=5433;Database=postgres;Username=postgres;Password=...;"
    }
    

    Port 0 has the operating system pick a free port, so two runs side by side don't collide. A loopback ListenOn keeps the service to this machine: it then listens on that address alone. Name only the engines you have, and only servers no other DbPool service owns: a second service on a server refuses to start.

  3. Start it with its standard input redirected, and keep that open for as long as the service should run:

    dotnet tool run compze-dbpool-service run --configuration <file> --address-file <file> --stop-when-stdin-closes
    

    (<folder>/compze-dbpool-service run … for a tool path install.) Name an address file that doesn't exist yet.

    Start it with the runtime's default socket completions. A parent that sets DOTNET_SYSTEM_NET_SOCKETS_INLINE_COMPLETIONS removes it from the child's environment, as startInfo.Environment.Remove("DOTNET_SYSTEM_NET_SOCKETS_INLINE_COMPLETIONS") does: with it, MySqlConnector deadlocks the service as it stops while a MySQL statement is under way.

  4. Wait for the address file. Once the service runs, it writes the address there whole, such as 127.0.0.1:52817, and deletes the file as it stops. If the process exits first, what it wrote to its standard output and error tells why.

  5. Build the test projects with that address as their CompzeDbPoolService, as dotnet test -p:CompzeDbPoolService=127.0.0.1:52817 does: the build puts it in each test project's runtimeconfig.json. A run with --no-build keeps the address of the build before it. Nothing else on the client side changes.

  6. Close its standard input to stop it. It stops and exits with 0. Your process ending closes the input too, so a service never outlives the run that started it. Killing it, its process tree under dotnet tool run, loses nothing either: the reservations were in its memory alone, the SQL server ends its lock with its connection, and the next service resets the databases it finds. It leaves its address file then.

Read its standard output and error as it runs, or send them to a file: it logs there, and a pipe nobody reads stalls it once full.

License

Apache-2.0

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
0.19.0-alpha 0 12/5/2026
0.18.1-alpha 0 12/5/2026
0.18.0-alpha 0 12/5/2026
0.17.1-alpha 0 12/5/2026
0.17.0-alpha 0 12/5/2026
0.16.0-alpha 0 12/5/2026
0.15.1-alpha 0 12/5/2026
0.15.0-alpha 0 12/5/2026
0.14.0-alpha 0 12/5/2026
0.5.2-alpha 7 12/5/2026
0.5.1-alpha 31 12/5/2026
0.5.0-alpha 77 12/5/2026
0.4.0-alpha 65 12/5/2026
0.3.5-alpha 54 12/5/2026
0.3.4-alpha 60 12/4/2026
0.3.3-alpha 52 12/4/2026
0.3.2-alpha 71 12/4/2026
0.3.1-alpha 84 12/4/2026
0.3.0-alpha 49 12/4/2026
0.2.5-alpha 52 12/4/2026
Loading failed