Fix race condition in munin output.
The munin server used the same structure in two goroutines at once causing possible data corruption. A copy of the structure is now used by the second goroutine instead.
This commit is contained in:
29
plugins/munin/munin_test.go
Normal file
29
plugins/munin/munin_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package munin
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/diebietse/invertergui/mk2driver"
|
||||
)
|
||||
|
||||
func TestServer(t *testing.T) {
|
||||
|
||||
mockMk2 := mk2driver.NewMk2Mock()
|
||||
muninServer := NewMunin(mockMk2)
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(muninServer.ServeMuninHTTP))
|
||||
defer ts.Close()
|
||||
|
||||
res, err := http.Get(ts.URL)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, err = ioutil.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user