From 89a9b98b35f24e2bbfcc9f4b7a8b1f8728115810 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 27 Feb 2016 16:34:20 -0600 Subject: [PATCH] Switched test code over to using ServerManager. Fixed some bugs found testing ServerManager. --- dospin.go | 16 ++++++---------- servermanager.go | 11 +++++++++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/dospin.go b/dospin.go index 6882df1..13a872f 100644 --- a/dospin.go +++ b/dospin.go @@ -32,16 +32,12 @@ func main() { } dh := NewDropletHandler(settings) + sm := NewServerManager("minecraft", dh, settings) + go sm.Serve() - ip, err := dh.Spinup("minecraft") - if err != nil { - log.Println("Error:", err) - return - } - log.Println("IP: " + ip) + sm.Spinup() + sm.Spindown() - if err := dh.Spindown("minecraft"); err != nil { - log.Println("Error:", err) - return - } + sm.Stop() + sm.Done() } diff --git a/servermanager.go b/servermanager.go index b6364f9..096d985 100644 --- a/servermanager.go +++ b/servermanager.go @@ -19,7 +19,7 @@ type ServerManager struct { name string ports []int in chan int - out chan int + done chan interface{} usageScore int // spin down server when this reaches 0 server ServerHandler } @@ -27,8 +27,9 @@ type ServerManager struct { func NewServerManager(name string, server ServerHandler, settings Settings) *ServerManager { sm := new(ServerManager) + sm.name = name sm.in = make(chan int) - sm.out = make(chan int) + sm.done = make(chan interface{}) sm.usageScore = 5 sm.server = server @@ -52,6 +53,7 @@ func (me *ServerManager) Serve() { running = me.serveAction(action) } } + me.done <- 42 } /* @@ -75,6 +77,10 @@ func (me *ServerManager) Stop() { me.in <- SERVERMANAGER_STOP } +func (me *ServerManager) Done() { + <-me.done +} + func (me *ServerManager) addPortForwards(ip string) { } @@ -87,6 +93,7 @@ func (me *ServerManager) serveAction(action int) bool { case SERVERMANAGER_SPINUP: ip, err := me.server.Spinup(me.name) if err == nil { + log.Println("ServerManager: Got IP for", me.name, ":", ip) me.addPortForwards(ip) } else { log.Println("ServerManager: Could not spin up "+me.name+":", err)