Skip to content

Commit

Permalink
Added LinkPreview feature (#467)
Browse files Browse the repository at this point in the history
* Added LinkPreview feature

Posts will randomly contain links now.

Also made it part of the deployment config.

* Tune percent chance of link
  • Loading branch information
agnivade authored Oct 15, 2021
1 parent d9503a6 commit 689d4e6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions deployment/terraform/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ func (t *Terraform) updateAppConfig(ip string, sshc *ssh.Client, jobServerEnable
cfg.ServiceSettings.IdleTimeout = model.NewInt(90)
cfg.ServiceSettings.EnableLocalMode = model.NewBool(true)
cfg.ServiceSettings.CollapsedThreads = model.NewString(model.CollapsedThreadsDefaultOn)
cfg.ServiceSettings.EnableLinkPreviews = model.NewBool(true)
cfg.EmailSettings.SMTPServer = model.NewString(t.output.MetricsServer.PrivateIP)
cfg.EmailSettings.SMTPPort = model.NewString("2500")

Expand Down
6 changes: 6 additions & 0 deletions loadtest/control/simulcontroller/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,12 @@ func createMessage(u user.User, channel *model.Channel, isReply bool) (string, e
}
message = "@" + user.Username + " "
}

// 10% of messages will contain a link.
if rand.Float64() < 0.10 {
message = control.AddLink(message)
}

message += genMessage(isReply)
return message, nil
}
Expand Down
17 changes: 17 additions & 0 deletions loadtest/control/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ var (
words = []string{}
emojis = []string{":grinning:", ":slightly_smiling_face:", ":smile:", ":sunglasses:"}
serverVersionRE = regexp.MustCompile(`\d+.\d+\.\d+`)
links = []string{
"https://github.com/mattermost/mattermost-server",
"https://www.youtube.com/watch?v=-5jompL6G-k",
"https://www.youtube.com/watch?v=GKLyAVHgNzY",
"https://mattermost.com",
"https://developers.mattermost.com",
"https://golang.org",
"https://reactjs.org",
}
)

// getErrOrigin returns a string indicating the location of the error that
Expand Down Expand Up @@ -138,6 +147,14 @@ func GenerateRandomSentences(count int) string {
return random[:len(random)-1] + "."
}

// AddLink appends a link to a string to test the LinkPreview feature.
func AddLink(input string) string {
n := rand.Int() % len(links)
link := links[n]

return input + " " + link + " "
}

// SelectWeighted does a random weighted selection on a given slice of weights.
func SelectWeighted(weights []int) (int, error) {
var sum int
Expand Down
8 changes: 8 additions & 0 deletions loadtest/control/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ func TestGenerateRandomSentences(t *testing.T) {
require.Equal(t, s[0], "🙂")
}

func TestAddLink(t *testing.T) {
msg := "hello world"
out := AddLink(msg)
words := strings.Split(out, " ")
require.Len(t, words, 4)
assert.Contains(t, links, words[2])
}

func TestSelectWeighted(t *testing.T) {
t.Run("empty weights", func(t *testing.T) {
idx, err := SelectWeighted([]int{})
Expand Down

0 comments on commit 689d4e6

Please sign in to comment.