X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/ca812f58e63bd4673bb62aa8528e07d6020bfc9a..7b4ec6d3c3ed209a42f542e1b646b8e672847fea:/services/ws/event_source_test.go diff --git a/services/ws/event_source_test.go b/services/ws/event_source_test.go index ee1da08bf1..ac5d130d61 100644 --- a/services/ws/event_source_test.go +++ b/services/ws/event_source_test.go @@ -1,12 +1,18 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + package main import ( "database/sql" "fmt" + "os" + "path/filepath" "sync" "time" - "git.curoverse.com/arvados.git/sdk/go/config" + "git.curoverse.com/arvados.git/sdk/go/arvados" check "gopkg.in/check.v1" ) @@ -14,43 +20,31 @@ var _ = check.Suite(&eventSourceSuite{}) type eventSourceSuite struct{} -func testDBConfig() (pgConfig, error) { - var railsDB struct { - Test struct { - Database string - Username string - Password string - Host string - } - } - err := config.LoadFile(&railsDB, "../api/config/database.yml") +func testDBConfig() arvados.PostgreSQLConnection { + cfg, err := arvados.GetConfig(filepath.Join(os.Getenv("WORKSPACE"), "tmp", "arvados.yml")) if err != nil { - return nil, err + panic(err) } - cfg := pgConfig{ - "dbname": railsDB.Test.Database, - "host": railsDB.Test.Host, - "password": railsDB.Test.Password, - "user": railsDB.Test.Username, + cc, err := cfg.GetCluster("zzzzz") + if err != nil { + panic(err) } - return cfg, nil + return cc.PostgreSQL.Connection } -func testDB() (*sql.DB, error) { - cfg, err := testDBConfig() +func testDB() *sql.DB { + db, err := sql.Open("postgres", testDBConfig().String()) if err != nil { - return nil, err + panic(err) } - return sql.Open("postgres", cfg.ConnectionString()) + return db } func (*eventSourceSuite) TestEventSource(c *check.C) { - cfg, err := testDBConfig() - if err != nil { - c.Fatal(err) - } + cfg := testDBConfig() + db := testDB() pges := &pgEventSource{ - DataSource: cfg.ConnectionString(), + DataSource: cfg.String(), QueueSize: 4, } go pges.Run() @@ -59,16 +53,9 @@ func (*eventSourceSuite) TestEventSource(c *check.C) { sinks[i] = pges.NewSink() } - // wait for listener to start, as evidenced by queue channel - // appearing (relying on internal implementation detail here) - for deadline := time.Now().Add(10 * time.Second); pges.queue == nil; time.Sleep(10 * time.Millisecond) { - c.Assert(time.Now().After(deadline), check.Equals, false) - } + pges.WaitReady() defer pges.cancel() - db, err := testDB() - c.Assert(err, check.IsNil) - done := make(chan bool, 1) go func() { @@ -114,4 +101,6 @@ func (*eventSourceSuite) TestEventSource(c *check.C) { case <-time.After(10 * time.Second): c.Fatal("timed out") } + + c.Check(pges.DBHealth(), check.IsNil) }