<commit_before>package sensormonitor

import (
	"testing"
	"time"

	"github.com/stampzilla/stampzilla-go/nodes/stampzilla-server/notifications"
	"github.com/stampzilla/stampzilla-go/pkg/notifier"
	"github.com/stretchr/testify/assert"
)

type senderStub struct {
	log []string
}

func (s *senderStub) Send(msg interface{}) {
	if n, ok := msg.(notifications.Notification); ok {
		s.log = append(s.log, n.Message)
	}
}

func TestSensorDead(t *testing.T) {

	sender := &senderStub{}
	notify := notifier.New(sender)
	sm := New(notify)
	sm.MonitorSensors = []int{10}
	sm.Start()

	sm.Alive(10)
	time.Sleep(20 * time.Millisecond)

	sm.CheckDead("10ms")
	assert.Equal(t, "Sensor 10 has not been updated in 10ms", sender.log[0])
}

func TestSensorNotDead(t *testing.T) {

	sender := &senderStub{}
	notify := notifier.New(sender)
	sm := New(notify)
	sm.MonitorSensors = []int{10}
	sm.Start()

	sm.Alive(10)
	time.Sleep(10 * time.Millisecond)

	sm.CheckDead("20ms")

	assert.Empty(t, sender.log)
}
func TestNotificationSendOnlyOnce(t *testing.T) {

	sender := &senderStub{}
	notify := notifier.New(sender)
	sm := New(notify)
	sm.MonitorSensors = []int{10}
	sm.Start()

	sm.Alive(10)
	time.Sleep(20 * time.Millisecond)

	sm.CheckDead("10ms")
	sm.CheckDead("10ms")
	assert.Len(t, sender.log, 1, "Ran two CheckDead, should notify only once")

	sm.Alive(10)
	time.Sleep(20 * time.Millisecond)
	sm.CheckDead("10ms")
	assert.Len(t, sender.log, 2)
}
func TestSensorOnlyMonitorSelected(t *testing.T) {

	sender := &senderStub{}
	notify := notifier.New(sender)
	sm := New(notify)
	sm.Start()

	sm.Alive(10)
	time.Sleep(20 * time.Millisecond)

	sm.CheckDead("10ms")
	assert.Empty(t, sender.log)<commit_msg>Fixed error in testcases<commit_after>package sensormonitor

import (
	"testing"
	"time"

	"github.com/stampzilla/stampzilla-go/nodes/stampzilla-server/notifications"
	"github.com/stampzilla/stampzilla-go/pkg/notifier"
	"github.com/stretchr/testify/assert"
)

type senderStub struct {
	log []string
}

func (s *senderStub) Send(msg interface{}) {
	if n, ok := msg.(notifications.Notification); ok {
		s.log = append(s.log, n.Message)
	}
}

func TestSensorDead(t *testing.T) {

	sender := &senderStub{}
	notify := notifier.New(sender)
	sm := New(notify)
	sm.MonitorSensors = []SensorConfig{SensorConfig{
		Id:   10,
		Name: "Tio",
	}}
	sm.Start()

	sm.Alive(10)
	time.Sleep(20 * time.Millisecond)

	sm.CheckDead("10ms")
	assert.Equal(t, "Sensor 10 has not been updated in 10ms", sender.log[0])
}

func TestSensorNotDead(t *testing.T) {

	sender := &senderStub{}
	notify := notifier.New(sender)
	sm := New(notify)
	sm.MonitorSensors = []SensorConfig{SensorConfig{
		Id:   10,
		Name: "Tio",
	}}
	sm.Start()

	sm.Alive(10)
	time.Sleep(10 * time.Millisecond)

	sm.CheckDead("20ms")

	assert.Empty(t, sender.log)
}
func TestNotificationSendOnlyOnce(t *testing.T) {

	sender := &senderStub{}
	notify := notifier.New(sender)
	sm := New(notify)
	sm.MonitorSensors = []SensorConfig{SensorConfig{
		Id:   10,
		Name: "Tio",
	}}
	sm.Start()

	sm.Alive(10)
	time.Sleep(20 * time.Millisecond)

	sm.CheckDead("10ms")
	sm.CheckDead("10ms")
	assert.Len(t, sender.log, 1, "Ran two CheckDead, should notify only once")

	sm.Alive(10)
	time.Sleep(20 * time.Millisecond)
	sm.CheckDead("10ms")
	assert.Len(t, sender.log, 2)
}
func TestSensorOnlyMonitorSelected(t *testing.T) {

	sender := &senderStub{}
	notify := notifier.New(sender)
	sm := New(notify)
	sm.Start()

	sm.Alive(10)
	time.Sleep(20 * time.Millisecond)

	sm.CheckDead("10ms")
	assert.Empty(t, sender.log)
{'fraction_non_alphanumeric': 0.16425941659586518, 'fraction_numerical': 0.025488530161427356, 'mean_word_length': 4.606349206349206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7487995', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1401, 'n_words': 254}