Skip to content

Commit

Permalink
Test cases for Connect/Timeout and Echo notification
Browse files Browse the repository at this point in the history
Signed-off-by: Madhu Venugopal <madhu@socketplane.io>
  • Loading branch information
mavenugo committed Nov 11, 2014
1 parent eefd279 commit 0ce5e7f
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions ovs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,49 @@ import (
"log"
"os"
"testing"
"time"
)

func TestConnect(t *testing.T) {
if testing.Short() {
t.Skip()
}

timeoutChan := make(chan bool)
connected := make(chan bool)
go func() {
time.Sleep(10 * time.Second)
timeoutChan <- true
}()

go func() {
// Use Convenience params. Ignore failure even if any
_, err := Connect("", 0)
if err != nil {
log.Println("Couldnt establish OVSDB connection with Defult params. No big deal")
}
}()

go func() {
ovs, err := Connect(os.Getenv("DOCKER_IP"), int(6640))
if err != nil {
connected <- false
} else {
connected <- true
ovs.Disconnect()
}
}()

select {
case <-timeoutChan:
t.Error("Connection Timed Out")
case b := <-connected:
if !b {
t.Error("Couldnt connect to OVSDB Server")
}
}
}

func TestListDbs(t *testing.T) {
if testing.Short() {
t.Skip()
Expand Down Expand Up @@ -209,6 +250,51 @@ func TestMonitor(t *testing.T) {
ovs.Disconnect()
}

func TestNotify(t *testing.T) {
if testing.Short() {
t.Skip()
}

ovs, err := Connect(os.Getenv("DOCKER_IP"), int(6640))
if err != nil {
log.Fatal("Failed to Connect. error:", err)
panic(err)
}

notifyEchoChan := make(chan bool)

notifier := Notifier{notifyEchoChan}
ovs.Register(notifier)

timeoutChan := make(chan bool)
go func() {
time.Sleep(10 * time.Second)
timeoutChan <- true
}()

select {
case <-timeoutChan:
t.Error("No Echo message notify in 10 seconds")
case <-notifyEchoChan:
break
}
ovs.Disconnect()
}

type Notifier struct {
echoChan chan bool
}

func (n Notifier) Update(context interface{}, tableUpdates TableUpdates) {
}
func (n Notifier) Locked([]interface{}) {
}
func (n Notifier) Stolen([]interface{}) {
}
func (n Notifier) Echo([]interface{}) {
n.echoChan <- true
}

func TestDBSchemaValidation(t *testing.T) {

if testing.Short() {
Expand Down

0 comments on commit 0ce5e7f

Please sign in to comment.