1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.curoverse.com/arvados.git/sdk/go/arvados"
16 check "gopkg.in/check.v1"
19 var _ = check.Suite(&eventSourceSuite{})
21 type eventSourceSuite struct{}
23 func testDBConfig() arvados.PostgreSQLConnection {
24 cfg, err := arvados.GetConfig(filepath.Join(os.Getenv("WORKSPACE"), "tmp", "arvados.yml"))
28 cc, err := cfg.GetCluster("zzzzz")
32 return cc.PostgreSQL.Connection
35 func testDB() *sql.DB {
36 db, err := sql.Open("postgres", testDBConfig().String())
43 func (*eventSourceSuite) TestEventSource(c *check.C) {
46 pges := &pgEventSource{
47 DataSource: cfg.String(),
51 sinks := make([]eventSink, 18)
52 for i := range sinks {
53 sinks[i] = pges.NewSink()
59 done := make(chan bool, 1)
62 for i := range sinks {
63 _, err := db.Exec(fmt.Sprintf(`NOTIFY logs, '%d'`, i))
74 for si, s := range sinks {
75 go func(si int, s eventSink) {
77 defer sinks[si].Stop()
78 for i := 0; i <= si; i++ {
79 ev := <-sinks[si].Channel()
80 c.Logf("sink %d received event %d", si, i)
81 c.Check(ev.LogID, check.Equals, uint64(i))
84 // no matching row, null event
85 c.Check(row, check.IsNil)
87 c.Check(row, check.NotNil)
88 c.Check(row.ID, check.Equals, uint64(i))
89 c.Check(row.UUID, check.Not(check.Equals), "")
101 case <-time.After(10 * time.Second):
105 c.Check(pges.DBHealth(), check.IsNil)