Skip to content

Commit

Permalink
Event driven refactor (#80)
Browse files Browse the repository at this point in the history
* fix(nearest-lobby): Fixed the /find and /nearest endpoints (#55)

* feat(better-votes): Unlinked votes from specific updates (#63)

* hotifx(serializer): A kind of bad fix for the serialization of interfaces in AnounceVote events. (#65)

* hotfix(seralization): Interfaces don't serialize properly

* fix(empty-room): Fixed error on empty result.

* updated golden files

* DD-165: Tag visible order  (#67)

* Tag: visible, order

* Update golden

* removed two_gis

all 2gis functionality has been removed

* Fix tags save (#71)

* Optimising Psql queries (#72)

* Fix tags save (#71)

* Updated SQL requests, TODO: fix error in `RecommendPlaces`

* fixes

* fix db recommend request

---------

Co-authored-by: Vaniog <[email protected]>
Co-authored-by: Vaniog <[email protected]>

* New recommendations

* Merge classic and priceBound

* some drafts

* a lot of work

* e2e passed

* fix unused

* replace old code

* fix metrics

* state.Context tests

* fix fmt.Errorf

* Fuck reflect, generics welcome!

* s.metrics.ActiveConnections.Dec()

* mutex fix

---------

Co-authored-by: Mike de Geofroy <[email protected]>
Co-authored-by: Alex Dyakonov <[email protected]>
  • Loading branch information
3 people authored Jan 21, 2025
1 parent d171193 commit 9b8527c
Show file tree
Hide file tree
Showing 19 changed files with 867 additions and 841 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ go.work

# Dev
.env
bin
bin
e2e/*/ERROR_*.json
10 changes: 5 additions & 5 deletions e2e/1-lobby-join/lobby_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"dishdash.ru/e2e/sdk"
"dishdash.ru/internal/domain"
"dishdash.ru/internal/gateways/ws/event"
"dishdash.ru/internal/usecase/event"

socketio "github.com/googollee/go-socket.io"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -34,8 +34,8 @@ func LobbyJoin(t *testing.T) *sdk.SocketIOSession {
sioSess.AddUser(user1.Name)
sioSess.AddUser(user2.Name)

cli1.OnEvent(event.UserJoined, sioSess.SioAddFunc(user1.Name, event.UserJoined))
cli2.OnEvent(event.UserJoined, sioSess.SioAddFunc(user2.Name, event.UserJoined))
cli1.OnEvent(event.UserJoinedEvent, sioSess.SioAddFunc(user1.Name, event.UserJoinedEvent))
cli2.OnEvent(event.UserJoinedEvent, sioSess.SioAddFunc(user2.Name, event.UserJoinedEvent))

assert.NoError(t, cli1.Connect())
assert.NoError(t, cli2.Connect())
Expand All @@ -44,12 +44,12 @@ func LobbyJoin(t *testing.T) *sdk.SocketIOSession {
cli1Emit := sdk.EmitWithLogFunc(cli1, user1.Name)
cli2Emit := sdk.EmitWithLogFunc(cli2, user2.Name)

cli1Emit(event.JoinLobby, event.JoinLobbyEvent{
cli1Emit(event.JoinLobbyEvent, event.JoinLobby{
LobbyID: lobby.ID,
UserID: user1.ID,
})
sdk.Sleep()
cli2Emit(event.JoinLobby, event.JoinLobbyEvent{
cli2Emit(event.JoinLobbyEvent, event.JoinLobby{
LobbyID: lobby.ID,
UserID: user2.ID,
})
Expand Down
30 changes: 15 additions & 15 deletions e2e/2-lobby-swipe/lobby_swipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"dishdash.ru/e2e/sdk"
"dishdash.ru/internal/domain"
"dishdash.ru/internal/gateways/ws/event"
"dishdash.ru/internal/usecase/event"

socketio "github.com/googollee/go-socket.io"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -39,12 +39,12 @@ func LobbySwipe(t *testing.T) *sdk.SocketIOSession {
cli2.OnEvent(eventName, sioSess.SioAddFunc(user2.Name, eventName))
}

listenEvent(event.Error)
listenEvent(event.UserJoined)
listenEvent(event.StartSwipes)
listenEvent(event.SettingsUpdate)
listenEvent(event.Place)
listenEvent(event.VoteAnnounce)
listenEvent(event.ErrorEvent)
listenEvent(event.UserJoinedEvent)
listenEvent(event.StartSwipesEvent)
listenEvent(event.SettingsUpdateEvent)
listenEvent(event.PlaceEvent)
listenEvent(event.VoteAnnounceEvent)

assert.NoError(t, cli1.Connect())
assert.NoError(t, cli2.Connect())
Expand All @@ -53,14 +53,14 @@ func LobbySwipe(t *testing.T) *sdk.SocketIOSession {
cli2Emit := sdk.EmitWithLogFunc(cli2, user2.Name)

sioSess.NewStep("User1 join lobby")
cli1Emit(event.JoinLobby, event.JoinLobbyEvent{
cli1Emit(event.JoinLobbyEvent, event.JoinLobby{
LobbyID: lobby.ID,
UserID: user1.ID,
})
sdk.Sleep()

sioSess.NewStep("Settings update")
cli1Emit(event.SettingsUpdate, event.SettingsUpdateEvent{
cli1Emit(event.SettingsUpdateEvent, event.SettingsUpdate{
Location: lobby.Location,
PriceMin: 300,
PriceMax: 300,
Expand All @@ -70,24 +70,24 @@ func LobbySwipe(t *testing.T) *sdk.SocketIOSession {
sdk.Sleep()

sioSess.NewStep("User2 join lobby")
cli2Emit(event.JoinLobby, event.JoinLobbyEvent{
cli2Emit(event.JoinLobbyEvent, event.JoinLobby{
LobbyID: lobby.ID,
UserID: user2.ID,
})
sdk.Sleep()

sioSess.NewStep("Start swipes")
cli1Emit(event.StartSwipes)
cli1Emit(event.StartSwipesEvent)
sdk.Sleep()

sioSess.NewStep("Swipe like and dislike")
cli1Emit(event.Swipe, event.SwipeEvent{SwipeType: domain.LIKE})
cli2Emit(event.Swipe, event.SwipeEvent{SwipeType: domain.DISLIKE})
cli1Emit(event.SwipeEvent, event.Swipe{SwipeType: domain.LIKE})
cli2Emit(event.SwipeEvent, event.Swipe{SwipeType: domain.DISLIKE})
sdk.Sleep()

sioSess.NewStep("Swipe both likes")
cli1Emit(event.Swipe, event.SwipeEvent{SwipeType: domain.LIKE})
cli2Emit(event.Swipe, event.SwipeEvent{SwipeType: domain.LIKE})
cli1Emit(event.SwipeEvent, event.Swipe{SwipeType: domain.LIKE})
cli2Emit(event.SwipeEvent, event.Swipe{SwipeType: domain.LIKE})
sdk.Sleep()

assert.NoError(t, cli1.Close())
Expand Down
16 changes: 8 additions & 8 deletions e2e/3-lobby-vote/lobby_vote.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
{
"EventName": "voted",
"Data": {
"User": {
"user": {
"avatar": "avatar1",
"id": "id1",
"name": "user1"
Expand All @@ -103,7 +103,7 @@
{
"EventName": "voted",
"Data": {
"User": {
"user": {
"avatar": "avatar2",
"id": "id2",
"name": "user2"
Expand Down Expand Up @@ -185,7 +185,7 @@
{
"EventName": "voted",
"Data": {
"User": {
"user": {
"avatar": "avatar2",
"id": "id2",
"name": "user2"
Expand All @@ -197,7 +197,7 @@
{
"EventName": "voted",
"Data": {
"User": {
"user": {
"avatar": "avatar1",
"id": "id1",
"name": "user1"
Expand Down Expand Up @@ -430,7 +430,7 @@
{
"EventName": "voted",
"Data": {
"User": {
"user": {
"avatar": "avatar1",
"id": "id1",
"name": "user1"
Expand All @@ -442,7 +442,7 @@
{
"EventName": "voted",
"Data": {
"User": {
"user": {
"avatar": "avatar2",
"id": "id2",
"name": "user2"
Expand Down Expand Up @@ -524,7 +524,7 @@
{
"EventName": "voted",
"Data": {
"User": {
"user": {
"avatar": "avatar2",
"id": "id2",
"name": "user2"
Expand All @@ -536,7 +536,7 @@
{
"EventName": "voted",
"Data": {
"User": {
"user": {
"avatar": "avatar1",
"id": "id1",
"name": "user1"
Expand Down
35 changes: 17 additions & 18 deletions e2e/3-lobby-vote/lobby_vote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"dishdash.ru/e2e/sdk"

"dishdash.ru/internal/domain"
"dishdash.ru/internal/gateways/ws/event"
"dishdash.ru/internal/usecase"
"dishdash.ru/internal/usecase/event"
socketio "github.com/googollee/go-socket.io"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -40,10 +39,10 @@ func LobbyVote(t *testing.T) *sdk.SocketIOSession {
cli2.OnEvent(eventName, sioSess.SioAddFunc(user2.Name, eventName))
}

listenEvent(event.VoteAnnounce)
listenEvent(event.Voted)
listenEvent(event.VoteResult)
listenEvent(event.Finish)
listenEvent(event.VoteAnnounceEvent)
listenEvent(event.VotedEvent)
listenEvent(event.VoteResultEvent)
listenEvent(event.FinishEvent)

assert.NoError(t, cli1.Connect())
assert.NoError(t, cli2.Connect())
Expand All @@ -52,15 +51,15 @@ func LobbyVote(t *testing.T) *sdk.SocketIOSession {
cli2Emit := sdk.EmitWithLogFunc(cli2, user2.Name)

sioSess.NewStep("Joining lobby")
cli1Emit(event.JoinLobby, event.JoinLobbyEvent{
cli1Emit(event.JoinLobbyEvent, event.JoinLobby{
LobbyID: lobby.ID,
UserID: user1.ID,
})
cli2Emit(event.JoinLobby, event.JoinLobbyEvent{
cli2Emit(event.JoinLobbyEvent, event.JoinLobby{
LobbyID: lobby.ID,
UserID: user2.ID,
})
cli1Emit(event.SettingsUpdate, event.SettingsUpdateEvent{
cli1Emit(event.SettingsUpdateEvent, event.SettingsUpdate{
Location: lobby.Location,
PriceMin: 300,
PriceMax: 300,
Expand All @@ -70,27 +69,27 @@ func LobbyVote(t *testing.T) *sdk.SocketIOSession {
sdk.Sleep()

sioSess.NewStep("Start swipes")
cli1Emit(event.StartSwipes)
cli1Emit(event.StartSwipesEvent)
sdk.Sleep()

sioSess.NewStep("Swipe both likes (1)")
cli1Emit(event.Swipe, event.SwipeEvent{SwipeType: domain.LIKE})
cli2Emit(event.Swipe, event.SwipeEvent{SwipeType: domain.LIKE})
cli1Emit(event.SwipeEvent, event.Swipe{SwipeType: domain.LIKE})
cli2Emit(event.SwipeEvent, event.Swipe{SwipeType: domain.LIKE})
sdk.Sleep()

sioSess.NewStep("Vote like and dislike")
cli1Emit(event.Vote, event.VoteEvent{VoteID: 1, OptionID: usecase.OptionIDLike})
cli2Emit(event.Vote, event.VoteEvent{VoteID: 1, OptionID: usecase.OptionIDDislike})
cli1Emit(event.VoteEvent, event.Vote{VoteID: 1, OptionID: event.OptionIDLike})
cli2Emit(event.VoteEvent, event.Vote{VoteID: 1, OptionID: event.OptionIDDislike})
sdk.Sleep()

sioSess.NewStep("Swipe both likes (2)")
cli1Emit(event.Swipe, event.SwipeEvent{SwipeType: domain.LIKE})
cli2Emit(event.Swipe, event.SwipeEvent{SwipeType: domain.LIKE})
cli1Emit(event.SwipeEvent, event.Swipe{SwipeType: domain.LIKE})
cli2Emit(event.SwipeEvent, event.Swipe{SwipeType: domain.LIKE})
sdk.Sleep()

sioSess.NewStep("Vote both likes")
cli1Emit(event.Vote, event.VoteEvent{VoteID: 2, OptionID: usecase.OptionIDLike})
cli2Emit(event.Vote, event.VoteEvent{VoteID: 2, OptionID: usecase.OptionIDLike})
cli1Emit(event.VoteEvent, event.Vote{VoteID: 2, OptionID: event.OptionIDLike})
cli2Emit(event.VoteEvent, event.Vote{VoteID: 2, OptionID: event.OptionIDLike})
sdk.Sleep()

assert.NoError(t, cli1.Close())
Expand Down
36 changes: 18 additions & 18 deletions e2e/4-lobby-result/lobby_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"dishdash.ru/e2e/sdk"

"dishdash.ru/internal/domain"
"dishdash.ru/internal/gateways/ws/event"
"dishdash.ru/internal/usecase/event"
socketio "github.com/googollee/go-socket.io"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -39,8 +39,8 @@ func LobbyResult(t *testing.T) *sdk.SocketIOSession {
cli1.OnEvent(eventName, sioSess.SioAddFunc(user1.Name, eventName))
cli2.OnEvent(eventName, sioSess.SioAddFunc(user2.Name, eventName))
}
listenEvent(event.VoteAnnounce)
listenEvent(event.SettingsUpdate)
listenEvent(event.VoteAnnounceEvent)
listenEvent(event.SettingsUpdateEvent)

assert.NoError(t, cli1.Connect())
assert.NoError(t, cli2.Connect())
Expand All @@ -49,15 +49,15 @@ func LobbyResult(t *testing.T) *sdk.SocketIOSession {
cli2Emit := sdk.EmitWithLogFunc(cli2, user2.Name)

sioSess.NewStep("Joining lobby")
cli1Emit(event.JoinLobby, event.JoinLobbyEvent{
cli1Emit(event.JoinLobbyEvent, event.JoinLobby{
LobbyID: lobby.ID,
UserID: user1.ID,
})
cli2Emit(event.JoinLobby, event.JoinLobbyEvent{
cli2Emit(event.JoinLobbyEvent, event.JoinLobby{
LobbyID: lobby.ID,
UserID: user2.ID,
})
cli1Emit(event.SettingsUpdate, event.SettingsUpdateEvent{
cli1Emit(event.SettingsUpdateEvent, event.SettingsUpdate{
Location: lobby.Location,
PriceMin: 300,
PriceMax: 300,
Expand All @@ -67,21 +67,21 @@ func LobbyResult(t *testing.T) *sdk.SocketIOSession {
sdk.Sleep()

sioSess.NewStep("Start swipes")
cli1Emit(event.StartSwipes)
cli1Emit(event.StartSwipesEvent)
sdk.Sleep()

sioSess.NewStep("Swipe like and dislike")
cli1Emit(event.Swipe, event.SwipeEvent{SwipeType: domain.DISLIKE})
cli2Emit(event.Swipe, event.SwipeEvent{SwipeType: domain.LIKE})
cli1Emit(event.SwipeEvent, event.Swipe{SwipeType: domain.DISLIKE})
cli2Emit(event.SwipeEvent, event.Swipe{SwipeType: domain.LIKE})
sdk.Sleep()

sioSess.NewStep("Swipe both likes")
cli1Emit(event.Swipe, event.SwipeEvent{SwipeType: domain.LIKE})
cli2Emit(event.Swipe, event.SwipeEvent{SwipeType: domain.LIKE})
cli1Emit(event.SwipeEvent, event.Swipe{SwipeType: domain.LIKE})
cli2Emit(event.SwipeEvent, event.Swipe{SwipeType: domain.LIKE})
sdk.Sleep()

cli1Emit(event.LeaveLobby)
cli2Emit(event.LeaveLobby)
cli1Emit(event.LeaveLobbyEvent)
cli2Emit(event.LeaveLobbyEvent)
sdk.Sleep()

// leave to check if lobby will be finished
Expand All @@ -94,15 +94,15 @@ func LobbyResult(t *testing.T) *sdk.SocketIOSession {
listenEvent = func(eventName string) {
cli3.OnEvent(eventName, sioSess.SioAddFunc(user1.Name, eventName))
}
listenEvent(event.JoinLobby)
listenEvent(event.Finish)
listenEvent(event.SettingsUpdate)
listenEvent(event.Error)
listenEvent(event.JoinLobbyEvent)
listenEvent(event.FinishEvent)
listenEvent(event.SettingsUpdateEvent)
listenEvent(event.ErrorEvent)

sioSess.NewStep("Rejoin")
assert.NoError(t, cli3.Connect())
cli3Emit := sdk.EmitWithLogFunc(cli3, user1.Name)
cli3Emit(event.JoinLobby, event.JoinLobbyEvent{
cli3Emit(event.JoinLobbyEvent, event.JoinLobby{
LobbyID: lobby.ID,
UserID: user1.ID,
})
Expand Down
Loading

0 comments on commit 9b8527c

Please sign in to comment.