Exemple #1
0
// Setup an environment for testing the Queue component.
// The queue capacity is configured with capacity.
// A number of clients will be connected to the queue.
func SetupQueueFixture(t *testing.T, capacity int, clients int) *QueueFixture {
	var err error
	f := new(QueueFixture)
	// Setup queue
	t.Log("Setup queue")
	f.Queue = NewQueue()
	addr, err := pythia.LocalAddr()
	if err != nil {
		t.Fatal(err)
	}
	pythia.QueueAddr = addr
	go f.Queue.Run()
	// Setup clients
	t.Log("Setup initial clients")
	f.Clients = make([]*pytest.Conn, clients)
	for i := 0; i < clients; i++ {
		f.Clients[i] = pytest.DialRetry(t, addr)
	}
	return f
}
Exemple #2
0
// Setup an environment for testing the Pool component.
// The pool capacity is configured with capacity. The test will fail if the pool
// does not register correctly.
func SetupPoolFixture(t *testing.T, capacity int) *PoolFixture {
	var err error
	f := new(PoolFixture)
	// Setup mock queue
	t.Log("Setup queue")
	addr, err := pythia.LocalAddr()
	if err != nil {
		t.Fatal(err)
	}
	pythia.QueueAddr = addr
	f.Queue, err = pythia.Listen(addr)
	if err != nil {
		t.Fatal(err)
	}
	// Setup pool
	t.Log("Setup pool")
	f.Pool = NewPool()
	f.Pool.Capacity = capacity
	f.Pool.UmlPath = pytest.UmlPath
	f.Pool.EnvDir = pytest.VmDir
	f.Pool.TasksDir = pytest.TasksDir
	go f.Pool.Run()
	// Establish connection
	t.Log("Establish connection")
	conn, err := f.Queue.Accept()
	if err != nil {
		f.Queue.Close()
		t.Fatal(err)
	}
	f.Conn = &pytest.Conn{t, conn}
	// Wait for register-pool message
	f.Conn.Expect(2, pythia.Message{
		Message:  pythia.RegisterPoolMsg,
		Capacity: capacity,
	})
	return f
}