cleaning up
parent
e601a9dda0
commit
c4305e38ee
|
|
@ -3,7 +3,6 @@ package model_test
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -62,18 +61,18 @@ func TestFlashBurst(t *testing.T) {
|
||||||
f.Info(fmt.Sprintf("test-%d", i))
|
f.Info(fmt.Sprintf("test-%d", i))
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(2 * delay)
|
time.Sleep(5 * delay)
|
||||||
s, _, l, m := v.getMetrics()
|
s, c, l, m := v.getMetrics()
|
||||||
assert.Equal(t, count, s)
|
assert.Equal(t, count, s)
|
||||||
assert.Equal(t, model.FlashInfo, l)
|
assert.Equal(t, model.FlashInfo, l)
|
||||||
assert.Equal(t, fmt.Sprintf("test-%d", count), m)
|
assert.Equal(t, fmt.Sprintf("test-%d", count), m)
|
||||||
|
assert.Equal(t, 1, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
type flash struct {
|
type flash struct {
|
||||||
set, clear int
|
set, clear int
|
||||||
level model.FlashLevel
|
level model.FlashLevel
|
||||||
msg string
|
msg string
|
||||||
mx sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFlash() *flash {
|
func newFlash() *flash {
|
||||||
|
|
@ -81,15 +80,11 @@ func newFlash() *flash {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *flash) getMetrics() (int, int, model.FlashLevel, string) {
|
func (f *flash) getMetrics() (int, int, model.FlashLevel, string) {
|
||||||
f.mx.RLock()
|
|
||||||
defer f.mx.RUnlock()
|
|
||||||
return f.set, f.clear, f.level, f.msg
|
return f.set, f.clear, f.level, f.msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *flash) listen(c model.FlashChan) {
|
func (f *flash) listen(c model.FlashChan) {
|
||||||
for m := range c {
|
for m := range c {
|
||||||
f.mx.Lock()
|
|
||||||
{
|
|
||||||
if m.IsClear() {
|
if m.IsClear() {
|
||||||
f.clear++
|
f.clear++
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -97,6 +92,4 @@ func (f *flash) listen(c model.FlashChan) {
|
||||||
f.level, f.msg = m.Level, m.Text
|
f.level, f.msg = m.Level, m.Text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.mx.Unlock()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue