Skip to content
Snippets Groups Projects
Select Git revision
  • b2defd2a1de647cdf1e7b93aebca25520b7aed53
  • release default
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • master protected
  • XX-4688/DbEncoding
  • hotfix/update
  • @XX-4682/Files
  • hotfix/XX-4655
  • dev protected
  • project/HavenNotifications
  • XX-4602/SilentMessageType
  • jono/npmTest
  • wasmTest2
  • XX-4461/FileUpload
  • XX-4505/blockuser
  • XX-4441
  • Jakub/Emoji-CI-Test
  • testing/websockets
  • fastReg
  • fast-registration
  • NewHostPool
  • v0.3.22
  • v0.3.21
  • v0.3.20
  • v0.3.18
  • v0.3.17
  • v0.3.16
  • v0.3.15
  • v0.3.14
  • v0.3.13
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • 812b395df518ce096d01d5292596ca26f8fe92d9c4487ddfa515e190a51aa1a1
  • 76ba08e2dfa1798412a265404fa271840b52c035869111fce8e8cdb23a036a5a
41 results

convert.go

Blame
  • event_test.go 2.39 KiB
    ///////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                          //
    //                                                                           //
    // Use of this source code is governed by a license that can be found in the //
    // LICENSE file                                                              //
    ///////////////////////////////////////////////////////////////////////////////
    
    package event
    
    import (
    	"testing"
    	"time"
    )
    
    func TestEventReporting(t *testing.T) {
    	evts := make([]reportableEvent, 0) // used for convenience...
    	myCb := func(priority int, cat, ty, det string) {
    		evt := reportableEvent{
    			Priority:  priority,
    			Category:  cat,
    			EventType: ty,
    			Details:   det,
    		}
    		t.Logf("EVENT: %s", evt)
    		evts = append(evts, evt)
    	}
    
    	evtMgr := NewEventManager()
    	stop, _ := evtMgr.EventService()
    	// Register a callback
    	err := evtMgr.RegisterEventCallback("test", myCb)
    	if err != nil {
    		t.Errorf("TestEventReporting unexpected error: %+v", err)
    	}
    
    	// Send a few events
    	evtMgr.Report(10, "Hi", "TypityType", "I'm an event")
    	evtMgr.Report(1, "Hi", "TypeII", "Tag II errors are the worst")
    	evtMgr.Report(20, "Hi", "TypityType3", "eventy details")
    	evtMgr.Report(22, "Hi", "TypityType4", "I'm an event 2")
    
    	time.Sleep(100 * time.Millisecond)
    
    	if len(evts) != 4 {
    		t.Errorf("TestEventReporting: Got %d events, expected 4",
    			len(evts))
    	}
    
    	// Verify events are received
    	if evts[0].Priority != 10 {
    		t.Errorf("TestEventReporting: Expected priority 10, got: %s",
    			evts[0])
    	}
    	if evts[1].Category != "Hi" {
    		t.Errorf("TestEventReporting: Expected cat Hi, got: %s",
    			evts[1])
    	}
    	if evts[2].EventType != "TypityType3" {
    		t.Errorf("TestEventReporting: Expected TypeityType3, got: %s",
    			evts[2])
    	}
    	if evts[3].Details != "I'm an event 2" {
    		t.Errorf("TestEventReporting: Expected event 2, got: %s",
    			evts[3])
    	}
    
    	// Delete callback
    	evtMgr.UnregisterEventCallback("test")
    	// Send more events
    	evtMgr.Report(10, "Hi", "TypityType", "I'm an event")
    	evtMgr.Report(1, "Hi", "TypeII", "Tag II errors are the worst")
    	evtMgr.Report(20, "Hi", "TypityType3", "eventy details")
    	evtMgr.Report(22, "Hi", "TypityType4", "I'm an event 2")
    
    	time.Sleep(100 * time.Millisecond)
    
    	// Verify events are not received
    	if len(evts) != 4 {
    		t.Errorf("TestEventReporting: Got %d events, expected 4",
    			len(evts))
    	}
    	stop.Close()
    }