Add unit test for proxy and shutdown channel

* Proxy has initial unit test and more can be added
* Shutdown channel and cancellation added for proper shutdown of
the proxy

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2020-01-03 12:06:53 +00:00
parent 9d688b9ea6
commit 098baba7cc
3 changed files with 154 additions and 53 deletions

View File

@ -77,6 +77,7 @@ func runUp(_ *cobra.Command, _ []string) error {
shutdownTimeout := time.Second * 1
timeout := time.Second * 60
proxyDoneCh := make(chan bool)
wg := sync.WaitGroup{}
wg.Add(1)
@ -92,14 +93,18 @@ func runUp(_ *cobra.Command, _ []string) error {
if err != nil {
fmt.Println(err)
}
// Close proxy
proxyDoneCh <- true
time.AfterFunc(shutdownTimeout, func() {
wg.Done()
})
}()
gatewayURLChan := make(chan string, 1)
proxy := pkg.NewProxy(timeout)
go proxy.Start(gatewayURLChan)
proxyPort := 8080
proxy := pkg.NewProxy(proxyPort, timeout)
go proxy.Start(gatewayURLChan, proxyDoneCh)
go func() {
wd, _ := os.Getwd()
@ -119,7 +124,7 @@ func runUp(_ *cobra.Command, _ []string) error {
}
}
log.Printf("[up] Sending %s to proxy\n", host)
gatewayURLChan <- host
gatewayURLChan <- host + ":8080"
close(gatewayURLChan)
}()