func (s *RethinkSuite) TestClusterRecoverAfterNoNodes(c *test.C) { session, err := Connect(ConnectOpts{ Addresses: []string{url, url2}, DiscoverHosts: true, NodeRefreshInterval: time.Second, }) c.Assert(err, test.IsNil) t := time.NewTimer(time.Second * 30) hasHadZeroNodes := false for { select { // Fail if deadline has passed case <-t.C: c.Fatal("No node was added to the cluster") default: // Check if there are no nodes if len(session.cluster.GetNodes()) == 0 { hasHadZeroNodes = true } // Pass if another node was added if len(session.cluster.GetNodes()) >= 1 && hasHadZeroNodes { return } } } }
func (s *RethinkSuite) TestTableChangesExitNoResults(c *test.C) { DB("test").TableDrop("changes").Exec(session) DB("test").TableCreate("changes").Exec(session) var n int res, err := DB("test").Table("changes").Changes().Run(session) if err != nil { c.Fatal(err.Error()) } c.Assert(res.Type(), test.Equals, "Feed") change := make(chan ChangeResponse) // Close cursor after one second go func() { <-time.After(time.Second) res.Close() }() // Listen for changes res.Listen(change) for _ = range change { n++ } if res.Err() == nil { c.Fatal("No error returned, expected connection closed") } c.Assert(n, test.Equals, 0) }
func (s *RethinkSuite) TestTableChanges(c *test.C) { DB("test").TableDrop("changes").Exec(session) DB("test").TableCreate("changes").Exec(session) var n int res, err := DB("test").Table("changes").Changes().Run(session) if err != nil { c.Fatal(err.Error()) } c.Assert(res.Type(), test.Equals, "Feed") wg := &sync.WaitGroup{} wg.Add(1) // Use goroutine to wait for changes. Prints the first 10 results go func() { var response interface{} for n < 10 && res.Next(&response) { n++ } if res.Err() != nil { c.Fatal(res.Err()) } wg.Done() }() DB("test").Table("changes").Insert(map[string]interface{}{"n": 1}).Exec(session) DB("test").Table("changes").Insert(map[string]interface{}{"n": 2}).Exec(session) DB("test").Table("changes").Insert(map[string]interface{}{"n": 3}).Exec(session) DB("test").Table("changes").Insert(map[string]interface{}{"n": 4}).Exec(session) DB("test").Table("changes").Insert(map[string]interface{}{"n": 5}).Exec(session) DB("test").Table("changes").Insert(map[string]interface{}{"n": 6}).Exec(session) DB("test").Table("changes").Insert(map[string]interface{}{"n": 7}).Exec(session) DB("test").Table("changes").Insert(map[string]interface{}{"n": 8}).Exec(session) DB("test").Table("changes").Insert(map[string]interface{}{"n": 9}).Exec(session) DB("test").Table("changes").Insert(map[string]interface{}{"n": 10}).Exec(session) wg.Wait() c.Assert(n, test.Equals, 10) }
func (s *RethinkSuite) TestClusterDetectNewNode(c *test.C) { session, err := Connect(ConnectOpts{ Addresses: []string{url, url2}, DiscoverHosts: true, NodeRefreshInterval: time.Second, }) c.Assert(err, test.IsNil) t := time.NewTimer(time.Second * 30) for { select { // Fail if deadline has passed case <-t.C: c.Fatal("No node was added to the cluster") default: // Pass if another node was added if len(session.cluster.GetNodes()) >= 3 { return } } } }