Skip to content

Commit

Permalink
update consul test
Browse files Browse the repository at this point in the history
  • Loading branch information
xg.gao committed Jul 25, 2020
1 parent 7970243 commit 9632fd7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 33 deletions.
2 changes: 1 addition & 1 deletion metadata/report/consul/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (suite *consulMetadataReportTestSuite) testGetServiceDefinition() {

func test1(t *testing.T) {
consulAgent := consul.NewConsulAgent(t, 8500)
defer consulAgent.Close()
defer consulAgent.Shutdown()

url := newProviderRegistryUrl("localhost", 8500)
mf := extension.GetMetadataReportFactory("consul")
Expand Down
8 changes: 5 additions & 3 deletions registry/consul/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (suite *consulRegistryTestSuite) close() {
// register -> subscribe -> unregister
func test1(t *testing.T) {
consulAgent := consul.NewConsulAgent(t, registryPort)
defer consulAgent.Close()
defer consulAgent.Shutdown()

server := newServer(providerHost, providerPort)
defer server.close()
Expand All @@ -165,10 +165,10 @@ func test1(t *testing.T) {
suite.testListener(remoting.EventTypeDel)
}

// subscribe -> register
// subscribe -> register -> unregister
func test2(t *testing.T) {
consulAgent := consul.NewConsulAgent(t, registryPort)
defer consulAgent.Close()
defer consulAgent.Shutdown()

server := newServer(providerHost, providerPort)
defer server.close()
Expand All @@ -181,6 +181,8 @@ func test2(t *testing.T) {
suite.testNewProviderRegistry()
suite.testRegister()
suite.testListener(remoting.EventTypeAdd)
suite.testUnregister()
suite.testListener(remoting.EventTypeDel)
}

func TestConsulRegistry(t *testing.T) {
Expand Down
30 changes: 2 additions & 28 deletions remoting/consul/test_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package consul

import (
"io/ioutil"
"os"
"strconv"
"testing"
)
Expand All @@ -30,35 +28,11 @@ import (

// Consul agent, used for test, simulates
// an embedded consul server.
type ConsulAgent struct {
dataDir string
testAgent *agent.TestAgent
}

func NewConsulAgent(t *testing.T, port int) *ConsulAgent {
dataDir, _ := ioutil.TempDir("./", "agent")
func NewConsulAgent(t *testing.T, port int) *agent.TestAgent {
hcl := `
ports {
http = ` + strconv.Itoa(port) + `
}
data_dir = "` + dataDir + `"
`
testAgent := &agent.TestAgent{Name: t.Name(), DataDir: dataDir, HCL: hcl}
testAgent.Start(t)

consulAgent := &ConsulAgent{
dataDir: dataDir,
testAgent: testAgent,
}
return consulAgent
}

func (consulAgent *ConsulAgent) Close() error {
var err error

err = consulAgent.testAgent.Shutdown()
if err != nil {
return err
}
return os.RemoveAll(consulAgent.dataDir)
return agent.NewTestAgent(t, hcl)
}
2 changes: 1 addition & 1 deletion remoting/consul/test_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ import (

func TestNewConsulAgent(t *testing.T) {
consulAgent := NewConsulAgent(t, 8500)
err := consulAgent.Close()
err := consulAgent.Shutdown()
assert.NoError(t, err)
}

0 comments on commit 9632fd7

Please sign in to comment.