9 "git.curoverse.com/arvados.git/sdk/go/config"
10 check "gopkg.in/check.v1"
13 var _ = check.Suite(&eventSourceSuite{})
15 type eventSourceSuite struct{}
17 func testDBConfig() pgConfig {
26 err := config.LoadFile(&railsDB, "../api/config/database.yml")
31 "dbname": railsDB.Test.Database,
32 "host": railsDB.Test.Host,
33 "password": railsDB.Test.Password,
34 "user": railsDB.Test.Username,
39 func testDB() *sql.DB {
40 db, err := sql.Open("postgres", testDBConfig().ConnectionString())
47 func (*eventSourceSuite) TestEventSource(c *check.C) {
50 pges := &pgEventSource{
51 DataSource: cfg.ConnectionString(),
55 sinks := make([]eventSink, 18)
56 for i := range sinks {
57 sinks[i] = pges.NewSink()
63 done := make(chan bool, 1)
66 for i := range sinks {
67 _, err := db.Exec(fmt.Sprintf(`NOTIFY logs, '%d'`, i))
78 for si, s := range sinks {
79 go func(si int, s eventSink) {
81 defer sinks[si].Stop()
82 for i := 0; i <= si; i++ {
83 ev := <-sinks[si].Channel()
84 c.Logf("sink %d received event %d", si, i)
85 c.Check(ev.LogID, check.Equals, uint64(i))
88 // no matching row, null event
89 c.Check(row, check.IsNil)
91 c.Check(row, check.NotNil)
92 c.Check(row.ID, check.Equals, uint64(i))
93 c.Check(row.UUID, check.Not(check.Equals), "")
105 case <-time.After(10 * time.Second):