mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 01:57:02 +00:00
Add store.messages option for SMTP load testing
This commit is contained in:
@@ -18,6 +18,7 @@ type SmtpConfig struct {
|
|||||||
MaxRecipients int
|
MaxRecipients int
|
||||||
MaxIdleSeconds int
|
MaxIdleSeconds int
|
||||||
MaxMessageBytes int
|
MaxMessageBytes int
|
||||||
|
StoreMessages bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebConfig struct {
|
type WebConfig struct {
|
||||||
@@ -91,6 +92,7 @@ func LoadConfig(filename string) error {
|
|||||||
requireOption(messages, "smtp", "max.recipients")
|
requireOption(messages, "smtp", "max.recipients")
|
||||||
requireOption(messages, "smtp", "max.idle.seconds")
|
requireOption(messages, "smtp", "max.idle.seconds")
|
||||||
requireOption(messages, "smtp", "max.message.bytes")
|
requireOption(messages, "smtp", "max.message.bytes")
|
||||||
|
requireOption(messages, "smtp", "store.messages")
|
||||||
requireOption(messages, "web", "ip4.address")
|
requireOption(messages, "web", "ip4.address")
|
||||||
requireOption(messages, "web", "ip4.port")
|
requireOption(messages, "web", "ip4.port")
|
||||||
requireOption(messages, "web", "template.dir")
|
requireOption(messages, "web", "template.dir")
|
||||||
@@ -193,6 +195,13 @@ func parseSmtpConfig() error {
|
|||||||
return fmt.Errorf("Failed to parse [%v]%v: '%v'", section, option, err)
|
return fmt.Errorf("Failed to parse [%v]%v: '%v'", section, option, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
option = "store.messages"
|
||||||
|
flag, err := Config.Bool(section, option)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Failed to parse [%v]%v: '%v'", section, option, err)
|
||||||
|
}
|
||||||
|
smtpConfig.StoreMessages = flag
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ max.idle.seconds=30
|
|||||||
# Maximum allowable size of message body in bytes (including attachments)
|
# Maximum allowable size of message body in bytes (including attachments)
|
||||||
max.message.bytes=2048000
|
max.message.bytes=2048000
|
||||||
|
|
||||||
|
# Should we place messages into the datastore, or just throw them away
|
||||||
|
# (for load testing): true or false
|
||||||
|
store.messages=true
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
[web]
|
[web]
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ max.idle.seconds=300
|
|||||||
# Maximum allowable size of message body in bytes (including attachments)
|
# Maximum allowable size of message body in bytes (including attachments)
|
||||||
max.message.bytes=2048000
|
max.message.bytes=2048000
|
||||||
|
|
||||||
|
# Should we place messages into the datastore, or just throw them away
|
||||||
|
# (for load testing): true or false
|
||||||
|
store.messages=true
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
[web]
|
[web]
|
||||||
|
|
||||||
|
|||||||
@@ -296,6 +296,7 @@ func (ss *Session) dataHandler() {
|
|||||||
// Get a Mailbox and a new Message for each recipient
|
// Get a Mailbox and a new Message for each recipient
|
||||||
mailboxes := make([]Mailbox, ss.recipients.Len())
|
mailboxes := make([]Mailbox, ss.recipients.Len())
|
||||||
messages := make([]Message, ss.recipients.Len())
|
messages := make([]Message, ss.recipients.Len())
|
||||||
|
if ss.server.storeMessages {
|
||||||
i := 0
|
i := 0
|
||||||
for e := ss.recipients.Front(); e != nil; e = e.Next() {
|
for e := ss.recipients.Front(); e != nil; e = e.Next() {
|
||||||
recip := e.Value.(string)
|
recip := e.Value.(string)
|
||||||
@@ -310,6 +311,7 @@ func (ss *Session) dataHandler() {
|
|||||||
messages[i] = mb.NewMessage()
|
messages[i] = mb.NewMessage()
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ss.send("354 Start mail input; end with <CRLF>.<CRLF>")
|
ss.send("354 Start mail input; end with <CRLF>.<CRLF>")
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
@@ -329,10 +331,14 @@ func (ss *Session) dataHandler() {
|
|||||||
line := buf.Bytes()
|
line := buf.Bytes()
|
||||||
if string(line) == ".\r\n" {
|
if string(line) == ".\r\n" {
|
||||||
// Mail data complete
|
// Mail data complete
|
||||||
|
if ss.server.storeMessages {
|
||||||
for _, m := range messages {
|
for _, m := range messages {
|
||||||
m.Close()
|
m.Close()
|
||||||
expDeliveredTotal.Add(1)
|
expDeliveredTotal.Add(1)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
expDeliveredTotal.Add(1)
|
||||||
|
}
|
||||||
ss.send("250 Mail accepted for delivery")
|
ss.send("250 Mail accepted for delivery")
|
||||||
ss.info("Message size %v bytes", msgSize)
|
ss.info("Message size %v bytes", msgSize)
|
||||||
ss.reset()
|
ss.reset()
|
||||||
@@ -352,6 +358,7 @@ func (ss *Session) dataHandler() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Append to message objects
|
// Append to message objects
|
||||||
|
if ss.server.storeMessages {
|
||||||
for i, m := range messages {
|
for i, m := range messages {
|
||||||
if err := m.Append(line); err != nil {
|
if err := m.Append(line); err != nil {
|
||||||
ss.error("Failed to append to mailbox %v: %v", mailboxes[i], err)
|
ss.error("Failed to append to mailbox %v: %v", mailboxes[i], err)
|
||||||
@@ -362,6 +369,7 @@ func (ss *Session) dataHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *Session) enterState(state State) {
|
func (ss *Session) enterState(state State) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type Server struct {
|
|||||||
maxIdleSeconds int
|
maxIdleSeconds int
|
||||||
maxMessageBytes int
|
maxMessageBytes int
|
||||||
dataStore DataStore
|
dataStore DataStore
|
||||||
|
storeMessages bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raw stat collectors
|
// Raw stat collectors
|
||||||
@@ -43,7 +44,8 @@ func New() *Server {
|
|||||||
ds := NewFileDataStore()
|
ds := NewFileDataStore()
|
||||||
cfg := config.GetSmtpConfig()
|
cfg := config.GetSmtpConfig()
|
||||||
return &Server{dataStore: ds, domain: cfg.Domain, maxRecips: cfg.MaxRecipients,
|
return &Server{dataStore: ds, domain: cfg.Domain, maxRecips: cfg.MaxRecipients,
|
||||||
maxIdleSeconds: cfg.MaxIdleSeconds, maxMessageBytes: cfg.MaxMessageBytes}
|
maxIdleSeconds: cfg.MaxIdleSeconds, maxMessageBytes: cfg.MaxMessageBytes,
|
||||||
|
storeMessages: cfg.StoreMessages}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main listener loop
|
// Main listener loop
|
||||||
@@ -65,6 +67,10 @@ func (s *Server) Start() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !s.storeMessages {
|
||||||
|
log.Info("Load test mode active, messages will not be stored")
|
||||||
|
}
|
||||||
|
|
||||||
// Start retention scanner
|
// Start retention scanner
|
||||||
StartRetentionScanner(s.dataStore)
|
StartRetentionScanner(s.dataStore)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user