<commit_before>package peergrouper

import (
	"fmt"
	"time"

	gc "launchpad.net/gocheck"

	coretesting "launchpad.net/juju-core/testing"
	"launchpad.net/juju-core/testing/testbase"
	"launchpad.net/juju-core/utils/voyeur"
	"launchpad.net/juju-core/worker"
)

//type workerJujuConnSuite struct {
//	testing.JujuConnSuite
//}
//
//var _ = gc.Suite(&workerJujuConnSuite{})
//
//func (s *workerJujuConnSuite) TestStartStop(c *gc.C) {
//	w, err := New(s.State)
//	c.Assert(err, gc.IsNil)
//	err = worker.Stop(w)
//	c.Assert(err, gc.IsNil)
//}

type workerSuite struct {
	testbase.LoggingSuite
}

var _ = gc.Suite(&workerSuite{})

func (s *workerSuite) TestSetsMembersInitially(c *gc.C) {
	st := newFakeState()
	var ids []string
	for i := 10; i < 13; i++ {
		id := fmt.Sprint(i)
		m := st.addMachine(id, true)
		m.setStateHostPort(fmt.Sprintf("0.1.2.%d", i))
		ids = append(ids, id)
	}
	st.setStateServers(ids...)
	st.session.Set(mkMembers("0v"))
	st.session.setStatus(mkStatuses("0p"))

	memberWatcher := st.session.members.Watch()
	mustNext(c, memberWatcher)
	c.Assert(memberWatcher.Value(), gc.HasLen, 1)

	logger.Infof("starting worker")
	w := newWorker(st)
	defer func() {
		c.Check(worker.Stop(w), gc.IsNil)
	}()

	mustNext(c, memberWatcher)
	c.Assert(memberWatcher.Value(), gc.HasLen, 3)
}

func mustNext(c *gc.C, w *voyeur.Watcher) (ok bool) {
	done := make(chan struct{})
	go func() {
		ok = w.Next()
		done <- struct{}{}
	}()
	select {
	case <-done:
		return
	case <-time.After(coretesting.LongWait):
		c.Fatalf("timed out waiting for value to be set")
	}
	panic("unreachable")
}
<commit_msg>worker/peergrouper: deepequal test members<commit_after>package peergrouper

import (
	"fmt"
	"time"

	gc "launchpad.net/gocheck"

	coretesting "launchpad.net/juju-core/testing"
	"launchpad.net/juju-core/testing/testbase"
	jc "launchpad.net/juju-core/testing/checkers"
	"launchpad.net/juju-core/utils/voyeur"
	"launchpad.net/juju-core/worker"
)

//type workerJujuConnSuite struct {
//	testing.JujuConnSuite
//}
//
//var _ = gc.Suite(&workerJujuConnSuite{})
//
//func (s *workerJujuConnSuite) TestStartStop(c *gc.C) {
//	w, err := New(s.State)
//	c.Assert(err, gc.IsNil)
//	err = worker.Stop(w)
//	c.Assert(err, gc.IsNil)
//}

type workerSuite struct {
	testbase.LoggingSuite
}

var _ = gc.Suite(&workerSuite{})

func (s *workerSuite) TestSetsMembersInitially(c *gc.C) {
	st := newFakeState()
	var ids []string
	for i := 10; i < 13; i++ {
		id := fmt.Sprint(i)
		m := st.addMachine(id, true)
		m.setStateHostPort(fmt.Sprintf("0.1.2.%d:%d", i, mongoPort))
		ids = append(ids, id)
	}
	st.setStateServers(ids...)
	st.session.Set(mkMembers("0v"))
	st.session.setStatus(mkStatuses("0p"))

	memberWatcher := st.session.members.Watch()
	mustNext(c, memberWatcher)
	c.Assert(memberWatcher.Value(), gc.HasLen, 1)

	logger.Infof("starting worker")
	w := newWorker(st)
	defer func() {
		c.Check(worker.Stop(w), gc.IsNil)
	}()

	mustNext(c, memberWatcher)
	c.Assert(memberWatcher.Value(), jc.DeepEquals, mkMembers("0v 1 2"))
}

func (s *workerSuite) TestMembersChange(c *gc.C) {
}

func mustNext(c *gc.C, w *voyeur.Watcher) (ok bool) {
	done := make(chan struct{})
	go func() {
		ok = w.Next()
		done <- struct{}{}
	}()
	select {
	case <-done:
		return
	case <-time.After(coretesting.LongWait):
		c.Fatalf("timed out waiting for value to be set")
	}
	panic("unreachable")
}

{'fraction_non_alphanumeric': 0.18265792610250298, 'fraction_numerical': 0.007151370679380214, 'mean_word_length': 4.109589041095891, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7228772', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1370, 'n_words': 249}