Commit 0f63e8d7 authored by shammash's avatar shammash

fix exit when half connected

parent 3bb444e4
Pipeline #969 passed with stages
in 1 minute 9 seconds
......@@ -190,10 +190,17 @@ func (notifier *IRCNotifier) Run() {
}
}
if notifier.Client.Connected() {
log.Printf("IRC client connected, quitting")
notifier.Client.Quit("see ya")
// Wait for disconnect to complete
<-notifier.sessionDownSignal
if notifier.sessionUp {
log.Printf("Session is up, wait for IRC disconnect to complete")
select {
case <-notifier.sessionDownSignal:
case <-time.After(notifier.Client.Config().Timeout):
log.Printf("Timeout while waiting for IRC disconnect to complete, stopping anyway")
}
}
}
notifier.StoppedRunning <- true
}
......@@ -652,3 +652,55 @@ func TestGhostAndIdentify(t *testing.T) {
t.Error("Ghosting did not happen correctly. Received commands:\n", strings.Join(server.Log, "\n"))
}
}
func TestStopRunningWhenHalfConnected(t *testing.T) {
server, port := makeTestServer(t)
config := makeTestIRCConfig(port)
notifier, _ := makeTestNotifier(t, config)
var testStep, holdQuitWait sync.WaitGroup
// Send a StopRunning request while the client is connected but the
// session is not up
testStep.Add(1)
holdUser := func(conn *bufio.ReadWriter, line *irc.Line) error {
log.Printf("=Server= NOT completing session")
testStep.Done()
return nil
}
server.SetHandler("USER", holdUser)
// Ignore quit, but wait for it to have deterministic test commands
holdQuitWait.Add(1)
holdQuit := func(conn *bufio.ReadWriter, line *irc.Line) error {
log.Printf("=Server= Ignoring quit")
holdQuitWait.Done()
return nil
}
server.SetHandler("QUIT", holdQuit)
go notifier.Run()
testStep.Wait()
notifier.StopRunning <- true
<-notifier.StoppedRunning
holdQuitWait.Wait()
// Client has left, cleanup the server side before stopping
server.Client.Close()
server.Stop()
expectedCommands := []string{
"NICK foo",
"USER foo 12 * :",
"QUIT :see ya",
}
if !reflect.DeepEqual(expectedCommands, server.Log) {
t.Error("Alert not sent correctly. Received commands:\n", strings.Join(server.Log, "\n"))
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment