func TestCuratorClients(t *testing.T) { log, stats := loggerAndStats() auth, storage := authAndStore(log, stats) config := binder.NewConfig() config.FlushPeriod = 5000 curator, err := New(NewConfig(), log, stats, auth, storage) if err != nil { t.Errorf("error: %v", err) return } doc, err := store.NewDocument("hello world") if err != nil { t.Errorf("error: %v", err) return } portal, err := curator.CreateDocument("", "", *doc, time.Second) *doc = portal.Document() if err != nil { t.Errorf("error: %v", err) } tform := func(i int) text.OTransform { return text.OTransform{ Position: 0, Version: i, Delete: 0, Insert: fmt.Sprintf("%v", i), } } if v, err := portal.SendTransform( tform(portal.BaseVersion()+1), time.Second, ); v != 2 || err != nil { t.Errorf("Send Transform error, v: %v, err: %v", v, err) } wg := sync.WaitGroup{} wg.Add(10) tformSending := 50 for i := 0; i < 10; i++ { if b, e := curator.EditDocument("test", "", doc.ID, time.Second); e != nil { t.Errorf("error: %v", e) } else { go goodClient(b, tformSending, t, &wg) } /*if b, e := curator.EditDocument("", doc.ID); e != nil { t.Errorf("error: %v", e) } else { go badClient(b, t, &wg) }*/ } wg.Add(25) for i := 0; i < 50; i++ { if i%2 == 0 { if b, e := curator.EditDocument( fmt.Sprintf("test%v", i), "", doc.ID, time.Second, ); e != nil { t.Errorf("error: %v", e) } else { go goodClient(b, tformSending-i, t, &wg) } /*if b, e := curator.EditDocument("", doc.ID); e != nil { t.Errorf("error: %v", e) } else { go badClient(b, t, &wg) }*/ } if v, err := portal.SendTransform(tform(i+3), time.Second); v != i+3 || err != nil { t.Errorf("Send Transform error, expected v: %v, got v: %v, err: %v", i+3, v, err) } } closeChan := make(chan bool) go func() { curator.Close() wg.Wait() closeChan <- true }() go func() { time.Sleep(1 * time.Second) closeChan <- false }() if closeStatus := <-closeChan; !closeStatus { t.Errorf("Timeout occured waiting for test finish.") } }
// NewConfig - Returns a fully defined curator configuration with the default values for each field. func NewConfig() Config { return Config{ BinderConfig: binder.NewConfig(), } }