Skip to content

Commit

Permalink
Merge bb4e7de into 6adf0fc
Browse files Browse the repository at this point in the history
  • Loading branch information
lftakakura authored Jan 7, 2019
2 parents 6adf0fc + bb4e7de commit 954535d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 18 deletions.
4 changes: 2 additions & 2 deletions eventforwarder/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func ForwardRoomEvent(
"roomId": room.ID,
"game": cachedScheduler.Scheduler.Game,
}
if eventType != PingTimeoutEvent {
if eventType != PingTimeoutEvent && eventType != OccupiedTimeoutEvent {
infos, err = room.GetRoomInfos(db, kubernetesClient, schedulerCache, cachedScheduler.Scheduler, addrGetter)
metadata["ipv6Label"] = infos["ipv6Label"]

Expand All @@ -124,7 +124,7 @@ func ForwardRoomEvent(
reportIpv6Status(infos, logger)
delete(infos, "ipv6Label")

} else { // fill host and port with zero values when pingTimeout event so it won't break the GRPCForwarder
} else { // fill host and port with zero values when pingTimeout or occupiedTimeout event so it won't break the GRPCForwarder
infos["host"] = ""
infos["port"] = int32(0)
}
Expand Down
47 changes: 44 additions & 3 deletions eventforwarder/forward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var _ = Describe("Forward", func() {
Expect(response.Message).To(Equal("success"))
})

It("should forward pingTimeout room event", func() {
It("should forward pingTimeout and occupiedTimeout room events", func() {
ctx := context.Background()
mockEventForwarder.EXPECT().Forward(
ctx,
Expand All @@ -88,9 +88,9 @@ var _ = Describe("Forward", func() {
reportersConstants.TagHostname: Hostname(),
reportersConstants.TagRoute: RouteRoomEvent,
reportersConstants.TagStatus: "success",
})
}).Times(2)

mockReporter.EXPECT().Report(reportersConstants.EventRPCDuration, gomock.Any())
mockReporter.EXPECT().Report(reportersConstants.EventRPCDuration, gomock.Any()).Times(2)

response, err := ForwardRoomEvent(
ctx,
Expand All @@ -109,6 +109,47 @@ var _ = Describe("Forward", func() {
Expect(err).NotTo(HaveOccurred())
Expect(response.Code).To(Equal(200))
Expect(response.Message).To(Equal("success"))

mockReporter.EXPECT().Report(reportersConstants.EventRPCStatus, map[string]interface{}{
reportersConstants.TagGame: gameName,
reportersConstants.TagScheduler: schedulerName,
reportersConstants.TagHostname: Hostname(),
reportersConstants.TagRoute: RouteRoomEvent,
reportersConstants.TagStatus: "success",
})

mockEventForwarder.EXPECT().Forward(
ctx,
models.StatusTerminated,
map[string]interface{}{
"host": "",
"port": int32(0),
"roomId": roomName,
"game": gameName,
"metadata": map[string]interface{}{},
},
metadata,
).Return(int32(200), "success", nil)

mockReporter.EXPECT().Report(reportersConstants.EventRPCDuration, gomock.Any())

response, err = ForwardRoomEvent(
ctx,
mockForwarders,
mockDB,
clientset,
room,
models.StatusTerminated,
OccupiedTimeoutEvent,
nil,
cache,
logger,
roomAddrGetter,
)

Expect(err).NotTo(HaveOccurred())
Expect(response.Code).To(Equal(200))
Expect(response.Message).To(Equal("success"))
})

It("should report fail if event forward fails", func() {
Expand Down
32 changes: 19 additions & 13 deletions watcher/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,18 +695,18 @@ var _ = Describe("Watcher", func() {
triggerMap[trigger.Type] = triggerSpec{
targetUsagePercent: trigger.Usage,
pointsAboveThresholdPercent: pointsAbove,
limit: trigger.Limit,
time: trigger.Time,
triggerType: trigger.Type,
limit: trigger.Limit,
time: trigger.Time,
triggerType: trigger.Type,
}
}
if _, exists := triggerMap[trigger.Type]; !exists {
triggerMap[trigger.Type] = triggerSpec{
targetUsagePercent: trigger.Usage,
pointsAboveThresholdPercent: pointsAbove,
limit: trigger.Limit,
time: trigger.Time,
triggerType: trigger.Type,
limit: trigger.Limit,
time: trigger.Time,
triggerType: trigger.Type,
}
}
}
Expand All @@ -721,18 +721,18 @@ var _ = Describe("Watcher", func() {
triggerMap[trigger.Type] = triggerSpec{
targetUsagePercent: trigger.Usage,
pointsAboveThresholdPercent: 100 - pointsAbove,
limit: trigger.Limit,
time: trigger.Time,
triggerType: trigger.Type,
limit: trigger.Limit,
time: trigger.Time,
triggerType: trigger.Type,
}
}
if _, exists := triggerMap[trigger.Type]; !exists {
triggerMap[trigger.Type] = triggerSpec{
targetUsagePercent: trigger.Usage,
pointsAboveThresholdPercent: 100 - pointsAbove,
limit: trigger.Limit,
time: trigger.Time,
triggerType: trigger.Type,
limit: trigger.Limit,
time: trigger.Time,
triggerType: trigger.Type,
}
}
down = append(down, triggerMap[trigger.Type])
Expand Down Expand Up @@ -3980,7 +3980,8 @@ var _ = Describe("Watcher", func() {
Expect(status).To(Equal(models.RoomTerminated))
Expect(infos["game"]).To(Equal(schedulerName))
Expect(expectedRooms).To(ContainElement(infos["roomId"]))
}).Times(len(expectedRooms))
}).Times(len(expectedRooms) * 2)

mockDb.EXPECT().Query(gomock.Any(), "SELECT * FROM schedulers WHERE name = ?", configYaml.Name).
Do(func(scheduler *models.Scheduler, query string, modifier string) {
scheduler.YAML = yaml1
Expand Down Expand Up @@ -4019,6 +4020,11 @@ var _ = Describe("Watcher", func() {
Expect(max).To(BeNumerically("~", ts, 1*time.Second))
}).Return(redis.NewStringSliceResult(expectedRooms, nil))

mockEventForwarder.EXPECT().Forward(gomock.Any(), models.RoomTerminated, gomock.Any(), gomock.Any()).Do(
func(ctx context.Context, status string, infos, fwdMetadata map[string]interface{}) {
Expect(status).To(Equal(models.RoomTerminated))
}).Times(len(expectedRooms))

mockDb.EXPECT().Query(gomock.Any(), "SELECT * FROM schedulers WHERE name = ?", configYaml.Name).
Do(func(scheduler *models.Scheduler, query string, modifier string) {
scheduler.YAML = yaml1
Expand Down

0 comments on commit 954535d

Please sign in to comment.