1
0
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:
James Hillyerd
2012-10-27 17:33:37 -07:00
parent ae05f75055
commit ec58e79874
5 changed files with 53 additions and 22 deletions

View File

@@ -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
}

View File

@@ -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]

View File

@@ -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]

View File

@@ -296,19 +296,21 @@ 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())
i := 0
for e := ss.recipients.Front(); e != nil; e = e.Next() {
recip := e.Value.(string)
mb, err := ss.server.dataStore.MailboxFor(recip)
if err != nil {
ss.error("Failed to open mailbox for %v", recip)
ss.send(fmt.Sprintf("451 Failed to open mailbox for %v", recip))
ss.reset()
return
if ss.server.storeMessages {
i := 0
for e := ss.recipients.Front(); e != nil; e = e.Next() {
recip := e.Value.(string)
mb, err := ss.server.dataStore.MailboxFor(recip)
if err != nil {
ss.error("Failed to open mailbox for %v", recip)
ss.send(fmt.Sprintf("451 Failed to open mailbox for %v", recip))
ss.reset()
return
}
mailboxes[i] = mb
messages[i] = mb.NewMessage()
i++
}
mailboxes[i] = mb
messages[i] = mb.NewMessage()
i++
}
ss.send("354 Start mail input; end with <CRLF>.<CRLF>")
@@ -329,8 +331,12 @@ func (ss *Session) dataHandler() {
line := buf.Bytes()
if string(line) == ".\r\n" {
// Mail data complete
for _, m := range messages {
m.Close()
if ss.server.storeMessages {
for _, m := range messages {
m.Close()
expDeliveredTotal.Add(1)
}
} else {
expDeliveredTotal.Add(1)
}
ss.send("250 Mail accepted for delivery")
@@ -352,13 +358,15 @@ func (ss *Session) dataHandler() {
return
}
// Append to message objects
for i, m := range messages {
if err := m.Append(line); err != nil {
ss.error("Failed to append to mailbox %v: %v", mailboxes[i], err)
ss.send("554 Something went wrong")
ss.reset()
// TODO: Should really cleanup the crap on filesystem...
return
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)
ss.send("554 Something went wrong")
ss.reset()
// TODO: Should really cleanup the crap on filesystem...
return
}
}
}
}

View File

@@ -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)