mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: pubsub reports dropped messages (#7660)
* Implementation; need linux tests Signed-off-by: Spike Curtis <spike@coder.com> * Pubsub with errors tests and fixes Signed-off-by: Spike Curtis <spike@coder.com> * Deal with test goroutines Signed-off-by: Spike Curtis <spike@coder.com> --------- Signed-off-by: Spike Curtis <spike@coder.com>
This commit is contained in:
@ -22,7 +22,8 @@ import (
|
||||
// Super unlikely, but it happened. See: https://github.com/coder/coder/runs/5375197003
|
||||
var openPortMutex sync.Mutex
|
||||
|
||||
// Open creates a new PostgreSQL server using a Docker container.
|
||||
// Open creates a new PostgreSQL database instance. With DB_FROM environment variable set, it clones a database
|
||||
// from the provided template. With the environment variable unset, it creates a new Docker container running postgres.
|
||||
func Open() (string, func(), error) {
|
||||
if os.Getenv("DB_FROM") != "" {
|
||||
// In CI, creating a Docker container for each test is slow.
|
||||
@ -51,7 +52,12 @@ func Open() (string, func(), error) {
|
||||
// so cleaning up the container will clean up the database.
|
||||
}, nil
|
||||
}
|
||||
return OpenContainerized(0)
|
||||
}
|
||||
|
||||
// OpenContainerized creates a new PostgreSQL server using a Docker container. If port is nonzero, forward host traffic
|
||||
// to that port to the database. If port is zero, allocate a free port from the OS.
|
||||
func OpenContainerized(port int) (string, func(), error) {
|
||||
pool, err := dockertest.NewPool("")
|
||||
if err != nil {
|
||||
return "", nil, xerrors.Errorf("create pool: %w", err)
|
||||
@ -63,12 +69,14 @@ func Open() (string, func(), error) {
|
||||
}
|
||||
|
||||
openPortMutex.Lock()
|
||||
// Pick an explicit port on the host to connect to 5432.
|
||||
// This is necessary so we can configure the port to only use ipv4.
|
||||
port, err := getFreePort()
|
||||
if err != nil {
|
||||
openPortMutex.Unlock()
|
||||
return "", nil, xerrors.Errorf("get free port: %w", err)
|
||||
if port == 0 {
|
||||
// Pick an explicit port on the host to connect to 5432.
|
||||
// This is necessary so we can configure the port to only use ipv4.
|
||||
port, err = getFreePort()
|
||||
if err != nil {
|
||||
openPortMutex.Unlock()
|
||||
return "", nil, xerrors.Errorf("get free port: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
|
||||
|
Reference in New Issue
Block a user