From 84a0cb60ed480ef8b97799833260eea93fcd06c2 Mon Sep 17 00:00:00 2001 From: Thomas Jager Date: Wed, 12 Feb 2014 08:40:30 +0100 Subject: [PATCH] Fix test cases. Added sleep before Quit --- irc_test.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/irc_test.go b/irc_test.go index da514fa..02fe5b4 100644 --- a/irc_test.go +++ b/irc_test.go @@ -3,11 +3,13 @@ package irc import ( // "github.com/thoj/go-ircevent" "testing" + "time" ) func TestConnection(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") irccon.VerboseCallbackHandler = true + irccon.Debug = true err := irccon.Connect("irc.freenode.net:6667") if err != nil { t.Fatal("Can't connect to freenode.") @@ -30,6 +32,7 @@ func TestConnection(t *testing.T) { func TestConnectionSSL(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") irccon.VerboseCallbackHandler = true + irccon.Debug = true irccon.UseTLS = true err := irccon.Connect("irc.freenode.net:7000") if err != nil { @@ -39,6 +42,7 @@ func TestConnectionSSL(t *testing.T) { irccon.AddCallback("366", func(e *Event) { irccon.Privmsg("#go-eventirc", "Test Message\n") + time.Sleep(2 * time.Second) irccon.Quit() }) @@ -48,7 +52,8 @@ func TestConnectionSSL(t *testing.T) { func TestRemoveCallback(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") irccon.VerboseCallbackHandler = true - + irccon.Debug = true + done := make(chan int, 10) irccon.AddCallback("TEST", func(e *Event) { done <- 1 }) @@ -62,7 +67,7 @@ func TestRemoveCallback(t *testing.T) { Code: "TEST", }) - var results []int + var results []int results = append(results, <-done) results = append(results, <-done) @@ -75,7 +80,8 @@ func TestRemoveCallback(t *testing.T) { func TestWildcardCallback(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") irccon.VerboseCallbackHandler = true - + irccon.Debug = true + done := make(chan int, 10) irccon.AddCallback("TEST", func(e *Event) { done <- 1 }) @@ -85,7 +91,7 @@ func TestWildcardCallback(t *testing.T) { Code: "TEST", }) - var results []int + var results []int results = append(results, <-done) results = append(results, <-done) @@ -98,11 +104,12 @@ func TestWildcardCallback(t *testing.T) { func TestClearCallback(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") irccon.VerboseCallbackHandler = true - + irccon.Debug = true + done := make(chan int, 10) irccon.AddCallback("TEST", func(e *Event) { done <- 0 }) - irccon.AddCallback("TEST", func(e *Event) { done <- 1 }) + irccon.AddCallback("TEST", func(e *Event) { done <- 1 }) irccon.ClearCallback("TEST") irccon.AddCallback("TEST", func(e *Event) { done <- 2 }) irccon.AddCallback("TEST", func(e *Event) { done <- 3 }) @@ -111,7 +118,7 @@ func TestClearCallback(t *testing.T) { Code: "TEST", }) - var results []int + var results []int results = append(results, <-done) results = append(results, <-done) @@ -119,4 +126,4 @@ func TestClearCallback(t *testing.T) { if len(results) != 2 || !(results[0] == 2 && results[1] == 3) { t.Error("Callbacks not cleared") } -} \ No newline at end of file +}