forked from yuxh/gearman-go
		
	Add skipping for integration tests when running unit tests
Run integration tests with the -integration flag
This commit is contained in:
		
							parent
							
								
									2dbf199260
								
							
						
					
					
						commit
						99d317427f
					
				@ -1,6 +1,8 @@
 | 
				
			|||||||
package client
 | 
					package client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"flag"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -8,9 +10,24 @@ const (
 | 
				
			|||||||
	TestStr = "Hello world"
 | 
						TestStr = "Hello world"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var client *Client
 | 
					var (
 | 
				
			||||||
 | 
						client              *Client
 | 
				
			||||||
 | 
						runIntegrationTests bool
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestMain(m *testing.M) {
 | 
				
			||||||
 | 
						integrationsTestFlag := flag.Bool("integration", false, "Run the integration tests (in addition to the unit tests)")
 | 
				
			||||||
 | 
						if integrationsTestFlag != nil {
 | 
				
			||||||
 | 
							runIntegrationTests = *integrationsTestFlag
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						code := m.Run()
 | 
				
			||||||
 | 
						os.Exit(code)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestClientAddServer(t *testing.T) {
 | 
					func TestClientAddServer(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	t.Log("Add local server 127.0.0.1:4730")
 | 
						t.Log("Add local server 127.0.0.1:4730")
 | 
				
			||||||
	var err error
 | 
						var err error
 | 
				
			||||||
	if client, err = New(Network, "127.0.0.1:4730"); err != nil {
 | 
						if client, err = New(Network, "127.0.0.1:4730"); err != nil {
 | 
				
			||||||
@ -22,6 +39,9 @@ func TestClientAddServer(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestClientEcho(t *testing.T) {
 | 
					func TestClientEcho(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	echo, err := client.Echo([]byte(TestStr))
 | 
						echo, err := client.Echo([]byte(TestStr))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Error(err)
 | 
							t.Error(err)
 | 
				
			||||||
@ -34,6 +54,9 @@ func TestClientEcho(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestClientDoBg(t *testing.T) {
 | 
					func TestClientDoBg(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	handle, err := client.DoBg("ToUpper", []byte("abcdef"), JobLow)
 | 
						handle, err := client.DoBg("ToUpper", []byte("abcdef"), JobLow)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Error(err)
 | 
							t.Error(err)
 | 
				
			||||||
@ -47,6 +70,9 @@ func TestClientDoBg(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestClientDo(t *testing.T) {
 | 
					func TestClientDo(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	jobHandler := func(job *Response) {
 | 
						jobHandler := func(job *Response) {
 | 
				
			||||||
		str := string(job.Data)
 | 
							str := string(job.Data)
 | 
				
			||||||
		if str == "ABCDEF" {
 | 
							if str == "ABCDEF" {
 | 
				
			||||||
@ -70,6 +96,9 @@ func TestClientDo(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestClientStatus(t *testing.T) {
 | 
					func TestClientStatus(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	status, err := client.Status("handle not exists")
 | 
						status, err := client.Status("handle not exists")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Error(err)
 | 
							t.Error(err)
 | 
				
			||||||
@ -105,6 +134,9 @@ func TestClientStatus(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestClientClose(t *testing.T) {
 | 
					func TestClientClose(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if err := client.Close(); err != nil {
 | 
						if err := client.Close(); err != nil {
 | 
				
			||||||
		t.Error(err)
 | 
							t.Error(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -9,6 +9,9 @@ var (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestPoolAdd(t *testing.T) {
 | 
					func TestPoolAdd(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	t.Log("Add servers")
 | 
						t.Log("Add servers")
 | 
				
			||||||
	c := 2
 | 
						c := 2
 | 
				
			||||||
	if err := pool.Add("tcp4", "127.0.0.1:4730", 1); err != nil {
 | 
						if err := pool.Add("tcp4", "127.0.0.1:4730", 1); err != nil {
 | 
				
			||||||
@ -24,6 +27,9 @@ func TestPoolAdd(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestPoolEcho(t *testing.T) {
 | 
					func TestPoolEcho(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	echo, err := pool.Echo("", []byte(TestStr))
 | 
						echo, err := pool.Echo("", []byte(TestStr))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Error(err)
 | 
							t.Error(err)
 | 
				
			||||||
@ -41,6 +47,9 @@ func TestPoolEcho(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestPoolDoBg(t *testing.T) {
 | 
					func TestPoolDoBg(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	addr, handle, err := pool.DoBg("ToUpper",
 | 
						addr, handle, err := pool.DoBg("ToUpper",
 | 
				
			||||||
		[]byte("abcdef"), JobLow)
 | 
							[]byte("abcdef"), JobLow)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@ -55,6 +64,9 @@ func TestPoolDoBg(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestPoolDo(t *testing.T) {
 | 
					func TestPoolDo(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	jobHandler := func(job *Response) {
 | 
						jobHandler := func(job *Response) {
 | 
				
			||||||
		str := string(job.Data)
 | 
							str := string(job.Data)
 | 
				
			||||||
		if str == "ABCDEF" {
 | 
							if str == "ABCDEF" {
 | 
				
			||||||
@ -77,6 +89,9 @@ func TestPoolDo(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestPoolStatus(t *testing.T) {
 | 
					func TestPoolStatus(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	status, err := pool.Status("127.0.0.1:4730", "handle not exists")
 | 
						status, err := pool.Status("127.0.0.1:4730", "handle not exists")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Error(err)
 | 
							t.Error(err)
 | 
				
			||||||
@ -114,6 +129,9 @@ func TestPoolStatus(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestPoolClose(t *testing.T) {
 | 
					func TestPoolClose(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
	if err := pool.Close(); err != nil {
 | 
						if err := pool.Close(); err != nil {
 | 
				
			||||||
		t.Error(err)
 | 
							t.Error(err)
 | 
				
			||||||
 | 
				
			|||||||
@ -53,5 +53,4 @@ func ExampleWorker() {
 | 
				
			|||||||
	w.Echo([]byte("Hello"))
 | 
						w.Echo([]byte("Hello"))
 | 
				
			||||||
	// Waiting results
 | 
						// Waiting results
 | 
				
			||||||
	wg.Wait()
 | 
						wg.Wait()
 | 
				
			||||||
	// Output: Hello
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -2,18 +2,35 @@ package worker
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"bytes"
 | 
						"bytes"
 | 
				
			||||||
 | 
						"flag"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var worker *Worker
 | 
					var (
 | 
				
			||||||
 | 
						worker              *Worker
 | 
				
			||||||
 | 
						runIntegrationTests bool
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
	worker = New(Unlimited)
 | 
						worker = New(Unlimited)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestMain(m *testing.M) {
 | 
				
			||||||
 | 
						integrationsTestFlag := flag.Bool("integration", false, "Run the integration tests (in addition to the unit tests)")
 | 
				
			||||||
 | 
						if integrationsTestFlag != nil {
 | 
				
			||||||
 | 
							runIntegrationTests = *integrationsTestFlag
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						code := m.Run()
 | 
				
			||||||
 | 
						os.Exit(code)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWorkerErrNoneAgents(t *testing.T) {
 | 
					func TestWorkerErrNoneAgents(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	err := worker.Ready()
 | 
						err := worker.Ready()
 | 
				
			||||||
	if err != ErrNoneAgents {
 | 
						if err != ErrNoneAgents {
 | 
				
			||||||
		t.Error("ErrNoneAgents expected.")
 | 
							t.Error("ErrNoneAgents expected.")
 | 
				
			||||||
@ -21,6 +38,9 @@ func TestWorkerErrNoneAgents(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWorkerAddServer(t *testing.T) {
 | 
					func TestWorkerAddServer(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	t.Log("Add local server 127.0.0.1:4730.")
 | 
						t.Log("Add local server 127.0.0.1:4730.")
 | 
				
			||||||
	if err := worker.AddServer(Network, "127.0.0.1:4730"); err != nil {
 | 
						if err := worker.AddServer(Network, "127.0.0.1:4730"); err != nil {
 | 
				
			||||||
		t.Error(err)
 | 
							t.Error(err)
 | 
				
			||||||
@ -33,6 +53,9 @@ func TestWorkerAddServer(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWorkerErrNoneFuncs(t *testing.T) {
 | 
					func TestWorkerErrNoneFuncs(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	err := worker.Ready()
 | 
						err := worker.Ready()
 | 
				
			||||||
	if err != ErrNoneFuncs {
 | 
						if err != ErrNoneFuncs {
 | 
				
			||||||
		t.Error("ErrNoneFuncs expected.")
 | 
							t.Error("ErrNoneFuncs expected.")
 | 
				
			||||||
@ -44,6 +67,9 @@ func foobar(job Job) ([]byte, error) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWorkerAddFunction(t *testing.T) {
 | 
					func TestWorkerAddFunction(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if err := worker.AddFunc("foobar", foobar, 0); err != nil {
 | 
						if err := worker.AddFunc("foobar", foobar, 0); err != nil {
 | 
				
			||||||
		t.Error(err)
 | 
							t.Error(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -57,12 +83,18 @@ func TestWorkerAddFunction(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWorkerRemoveFunc(t *testing.T) {
 | 
					func TestWorkerRemoveFunc(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if err := worker.RemoveFunc("foobar"); err != nil {
 | 
						if err := worker.RemoveFunc("foobar"); err != nil {
 | 
				
			||||||
		t.Error(err)
 | 
							t.Error(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWork(t *testing.T) {
 | 
					func TestWork(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	var wg sync.WaitGroup
 | 
						var wg sync.WaitGroup
 | 
				
			||||||
	worker.JobHandler = func(job Job) error {
 | 
						worker.JobHandler = func(job Job) error {
 | 
				
			||||||
		t.Logf("%s", job.Data())
 | 
							t.Logf("%s", job.Data())
 | 
				
			||||||
@ -80,6 +112,9 @@ func TestWork(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestLargeDataWork(t *testing.T) {
 | 
					func TestLargeDataWork(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	worker := New(Unlimited)
 | 
						worker := New(Unlimited)
 | 
				
			||||||
	defer worker.Close()
 | 
						defer worker.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -136,10 +171,16 @@ func TestLargeDataWork(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWorkerClose(t *testing.T) {
 | 
					func TestWorkerClose(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	worker.Close()
 | 
						worker.Close()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWorkWithoutReady(t *testing.T) {
 | 
					func TestWorkWithoutReady(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	other_worker := New(Unlimited)
 | 
						other_worker := New(Unlimited)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := other_worker.AddServer(Network, "127.0.0.1:4730"); err != nil {
 | 
						if err := other_worker.AddServer(Network, "127.0.0.1:4730"); err != nil {
 | 
				
			||||||
@ -193,6 +234,9 @@ func TestWorkWithoutReady(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWorkWithoutReadyWithPanic(t *testing.T) {
 | 
					func TestWorkWithoutReadyWithPanic(t *testing.T) {
 | 
				
			||||||
 | 
						if !runIntegrationTests {
 | 
				
			||||||
 | 
							t.Skip("To run this test, use: go test -integration")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	other_worker := New(Unlimited)
 | 
						other_worker := New(Unlimited)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	timeout := make(chan bool, 1)
 | 
						timeout := make(chan bool, 1)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user