-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scheduled post #848
base: master
Are you sure you want to change the base?
Scheduled post #848
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like some debug fmt.Println
statements are still left over from debugging. Let's clean them up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for all your work on this, great job! I left some comments below, and I also agree with Agniva: we should remove all the fmt.Println
lines.
{ | ||
name: "CreateScheduledPost", | ||
run: c.createScheduledPost, | ||
frequency: 0.2, | ||
minServerVersion: semver.MustParse("10.3.0"), | ||
}, | ||
{ | ||
name: "UpdateScheduledPost", | ||
run: c.updateScheduledPost, | ||
frequency: 0.1, | ||
minServerVersion: semver.MustParse("10.3.0"), | ||
}, | ||
{ | ||
name: "DeleteScheduledPost", | ||
run: c.deleteScheduledPost, | ||
frequency: 0.1, | ||
minServerVersion: semver.MustParse("10.3.0"), | ||
}, | ||
{ | ||
name: "SendScheduledPost", | ||
run: c.sendScheduledPost, | ||
frequency: 0.1, | ||
minServerVersion: semver.MustParse("10.3.0"), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these frequencies computed from real usage data? Or do we need to create a ticket to update them once this has more widespread usage?
if rand.Float64() < 0.02 { | ||
if err := control.AttachFilesToDraft(u, &scheduledPost.Draft); err != nil { | ||
fmt.Println("createScheduledPost: AttachFilesToDraft error", err) | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably move this 0.02 ratio to a global constant, we're using it in many places now.
if err := u.DeleteScheduledPost(scheduledPost.Id); err != nil { | ||
fmt.Println("deleteScheduledPost: DeleteScheduledPost error", err) | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
u.Store().DeleteScheduledPost(scheduledPost.Id) | ||
return control.UserActionResponse{Info: fmt.Sprintf("scheduled post deleted with id %v", scheduledPost.Id)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should update the store inside the user's function.
return control.UserActionResponse{Info: fmt.Sprintf("scheduled post deleted with id %v", scheduledPost.Id)} | ||
} | ||
|
||
func (c *SimulController) sendScheduledPost(u user.User) control.UserActionResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me see if I understood this action: it forces a post that was scheduled for the future to be sent immediately. If that's correct, could we come up with an action name that conveys that? Something like sendScheduledPostNow
or similar? Or maybe adding a comment, if that's not clear enough.
if err := u.DeleteScheduledPost(scheduledPost.Id); err != nil { | ||
fmt.Println("sendScheduledPost: DeleteScheduledPost error", err) | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
u.Store().DeleteScheduledPost(scheduledPost.Id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: we should update the store inside the user's DeleteScheduledPost
function
func (s *MemStore) DeleteScheduledPost(scheduledPostID string) { | ||
s.lock.Lock() | ||
defer s.lock.Unlock() | ||
|
||
for teamId := range s.scheduledPosts { | ||
if _, ok := s.scheduledPosts[teamId][scheduledPostID]; ok { | ||
delete(s.scheduledPosts[teamId], scheduledPostID) | ||
break | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know the team ID when deleting the post? We could skip the outer loop if we do.
id := scheduledPost.ChannelId | ||
if createdScheduledPost.RootId != "" { | ||
id = scheduledPost.RootId | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ChannelId
? Does this mean that we can schedule a single post per channel? This happens in UpdateScheduledPost
as well.
for teamIdInResponse := range scheduledPostsByTeam { | ||
for _, scheduledPost := range scheduledPostsByTeam[teamIdInResponse] { | ||
err := ue.store.SetScheduledPost(teamID, scheduledPost.Id, scheduledPost) | ||
if err != nil { | ||
fmt.Println("GetTeamScheduledPosts: SetScheduledPost error", err) | ||
return err | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't understand this code, so I took a look at the server code and saw that we use directChannels
as a special team ID here to get posts scheduled in DMs. Is this something that can break some assumptions elsewhere in this code? I suppose no, but wanted to double-check.
Nit: also, should we add a ue.store.SetScheduledPostsInTeam
so that we can pass it the whole slice of posts?
RootId: rootId, | ||
CreateAt: model.GetMillis(), | ||
}, | ||
ScheduledAt: loadtest.RandomFutureTime(17_28_00_000, 10), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does 17_28_00_000
mean?
@@ -87,3 +89,19 @@ func nextPowerOf2(val int) int { | |||
val++ | |||
return val | |||
} | |||
|
|||
// RandomFutureTime generates a random time between (now + xMilliseconds) to (now + xDays) in Unix milliseconds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can we use the name of the variables themselves? It took me a while to understand the comment
// RandomFutureTime generates a random time between (now + xMilliseconds) to (now + xDays) in Unix milliseconds. | |
// RandomFutureTime generates a random time between (now + millisecondsFromNow) to (now + uptoDaysFromNow) in Unix milliseconds. |
Summary
Adding scheduled posts support to load test tool.
Ticket Link
Fixes https://mattermost.atlassian.net/browse/MM-61486