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