Skip to content
Snippets Groups Projects
Commit db750a09 authored by benjamin's avatar benjamin
Browse files

hacked dummy message sender ramp down after sending 20 messages

parent 4dd4ba27
No related branches found
No related tags found
1 merge request!510Release
...@@ -61,6 +61,8 @@ type Manager struct { ...@@ -61,6 +61,8 @@ type Manager struct {
// Pauses/Resumes the dummy send thread when triggered // Pauses/Resumes the dummy send thread when triggered
statusChan chan bool statusChan chan bool
totalSent *uint64
// Interfaces // Interfaces
net cmix.Client net cmix.Client
store storage.Session store storage.Session
...@@ -96,6 +98,7 @@ func NewManager(maxNumMessages int, ...@@ -96,6 +98,7 @@ func NewManager(maxNumMessages int,
// function is a helper function for NewManager. // function is a helper function for NewManager.
func newManager(maxNumMessages int, avgSendDelta, randomRange time.Duration, func newManager(maxNumMessages int, avgSendDelta, randomRange time.Duration,
net cmix.Client, store storage.Session, rng *fastRNG.StreamGenerator) *Manager { net cmix.Client, store storage.Session, rng *fastRNG.StreamGenerator) *Manager {
numSent := uint64(8)
return &Manager{ return &Manager{
maxNumMessages: maxNumMessages, maxNumMessages: maxNumMessages,
avgSendDelta: avgSendDelta, avgSendDelta: avgSendDelta,
...@@ -105,6 +108,7 @@ func newManager(maxNumMessages int, avgSendDelta, randomRange time.Duration, ...@@ -105,6 +108,7 @@ func newManager(maxNumMessages int, avgSendDelta, randomRange time.Duration,
net: net, net: net,
store: store, store: store,
rng: rng, rng: rng,
totalSent: &numSent,
} }
} }
......
...@@ -35,6 +35,7 @@ func Test_newManager(t *testing.T) { ...@@ -35,6 +35,7 @@ func Test_newManager(t *testing.T) {
statusChanLen, cap(received.statusChan)) statusChanLen, cap(received.statusChan))
} }
received.statusChan = expected.statusChan received.statusChan = expected.statusChan
received.totalSent = nil
if !reflect.DeepEqual(expected, received) { if !reflect.DeepEqual(expected, received) {
t.Errorf("New manager does not match expected."+ t.Errorf("New manager does not match expected."+
......
...@@ -22,6 +22,11 @@ import ( ...@@ -22,6 +22,11 @@ import (
// Error messages for the Manager.sendThread and its helper functions. // Error messages for the Manager.sendThread and its helper functions.
const ( const (
numMsgsRngErr = "failed to generate random number of messages to send: %+v" numMsgsRngErr = "failed to generate random number of messages to send: %+v"
overrideAvgSendDelta = 10 * time.Minute
overrideRandomRange = 8 * time.Minute
overrideMaxNumMessages = 2
numSendsToOverride = 20
) )
// sendThread is a thread that sends the dummy messages at random intervals. // sendThread is a thread that sends the dummy messages at random intervals.
...@@ -32,6 +37,13 @@ func (m *Manager) sendThread(stop *stoppable.Single) { ...@@ -32,6 +37,13 @@ func (m *Manager) sendThread(stop *stoppable.Single) {
nextSendChanPtr := &(nextSendChan) nextSendChanPtr := &(nextSendChan)
for { for {
if numSent := atomic.LoadUint64(m.totalSent); numSent > numSendsToOverride {
m.avgSendDelta = overrideAvgSendDelta
m.randomRange = overrideRandomRange
m.maxNumMessages = overrideMaxNumMessages
}
select { select {
case status := <-m.statusChan: case status := <-m.statusChan:
if status { if status {
...@@ -71,6 +83,8 @@ func (m *Manager) sendThread(stop *stoppable.Single) { ...@@ -71,6 +83,8 @@ func (m *Manager) sendThread(stop *stoppable.Single) {
err := m.sendMessages() err := m.sendMessages()
if err != nil { if err != nil {
jww.ERROR.Printf("Failed to send dummy messages: %+v", err) jww.ERROR.Printf("Failed to send dummy messages: %+v", err)
} else {
atomic.AddUint64(m.totalSent, 1)
} }
}() }()
case <-stop.Quit(): case <-stop.Quit():
......
...@@ -40,6 +40,7 @@ func newTestManager(maxNumMessages int, avgSendDelta, randomRange time.Duration, ...@@ -40,6 +40,7 @@ func newTestManager(maxNumMessages int, avgSendDelta, randomRange time.Duration,
t *testing.T) *Manager { t *testing.T) *Manager {
store := storage.InitTestingSession(t) store := storage.InitTestingSession(t)
payloadSize := store.GetCmixGroup().GetP().ByteLen() payloadSize := store.GetCmixGroup().GetP().ByteLen()
n := uint64(0)
m := &Manager{ m := &Manager{
maxNumMessages: maxNumMessages, maxNumMessages: maxNumMessages,
avgSendDelta: avgSendDelta, avgSendDelta: avgSendDelta,
...@@ -48,6 +49,7 @@ func newTestManager(maxNumMessages int, avgSendDelta, randomRange time.Duration, ...@@ -48,6 +49,7 @@ func newTestManager(maxNumMessages int, avgSendDelta, randomRange time.Duration,
store: store, store: store,
net: newMockCmix(payloadSize), net: newMockCmix(payloadSize),
rng: fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG), rng: fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG),
totalSent: &n,
} }
return m return m
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment