Skip to content
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

Update events forwarder cache to run cleanup manually when cache expires #549

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: push
jobs:
unit:
name: Unit tests
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Set up Go
uses: actions/setup-go@v1
Expand All @@ -23,7 +23,7 @@ jobs:
run: bash <(curl -s https://codecov.io/bash)
integration:
name: Integration tests
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Set up Go
uses: actions/setup-go@v1
Expand All @@ -44,7 +44,7 @@ jobs:

runtime-integration:
name: Runtime Integration tests
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
Expand Down
3 changes: 2 additions & 1 deletion internal/adapters/events/forwarder_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type ForwarderClient struct {

// NewForwarderClient instantiate a new grpc forwarder client.
func NewForwarderClient() *ForwarderClient {
cache := cache.New(24*time.Hour, 25*time.Hour)
cache := cache.New(24*time.Hour, 0)
tobiasbu marked this conversation as resolved.
Show resolved Hide resolved
cache.OnEvicted(func(_key string, clientFromCache interface{}) {
ForwarderClient := clientFromCache.(*grpc.ClientConn)
ForwarderClient.Close()
Expand Down Expand Up @@ -150,6 +150,7 @@ func (f *ForwarderClient) getGrpcClient(address Address) (pb.GRPCForwarderClient
if err != nil {
return nil, err
}
f.c.DeleteExpired()
f.c.Set(string(address), client, cache.DefaultExpiration)
return pb.NewGRPCForwarderClient(client), nil
}
Expand Down
18 changes: 1 addition & 17 deletions internal/adapters/events/forwarder_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (

"testing"

"github.com/patrickmn/go-cache"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/topfreegames/maestro/internal/core/entities/forwarder"
Expand Down Expand Up @@ -131,9 +130,6 @@ func TestSendRoomReSync(t *testing.T) {
}

func TestForwarderClient_SendRoomStatus(t *testing.T) {
type fields struct {
c *cache.Cache
}
type args struct {
ctx context.Context
forwarder forwarder.Forwarder
Expand All @@ -142,17 +138,13 @@ func TestForwarderClient_SendRoomStatus(t *testing.T) {
tests := []struct {
name string
requestStubFile string
fields fields
args args
want *pb.Response
wantErr assert.ErrorAssertionFunc
}{
{
name: "return response with code 200 when request succeeds",
requestStubFile: "../../../test/data/events_mock/events-forwarder-grpc-send-room-status-success.json",
fields: fields{
c: cache.New(time.Minute, time.Minute),
},
args: args{
ctx: context.Background(),
forwarder: newForwarder(grpcMockAddress),
Expand All @@ -167,9 +159,6 @@ func TestForwarderClient_SendRoomStatus(t *testing.T) {
{
name: "return response with code 500 when request fails",
requestStubFile: "../../../test/data/events_mock/events-forwarder-grpc-send-room-status-failure.json",
fields: fields{
c: cache.New(time.Minute, time.Minute),
},
args: args{
ctx: context.Background(),
forwarder: newForwarder(grpcMockAddress),
Expand All @@ -184,9 +173,6 @@ func TestForwarderClient_SendRoomStatus(t *testing.T) {
{
name: "return error when connection establishment fails",
requestStubFile: "",
fields: fields{
c: cache.New(time.Minute, time.Minute),
},
args: args{
ctx: context.Background(),
forwarder: newForwarder(""),
Expand All @@ -204,9 +190,7 @@ func TestForwarderClient_SendRoomStatus(t *testing.T) {
)
require.NoError(t, err)
}
f := &ForwarderClient{
c: tt.fields.c,
}
f := NewForwarderClient()
tobiasbu marked this conversation as resolved.
Show resolved Hide resolved
got, err := f.SendRoomStatus(tt.args.ctx, tt.args.forwarder, &tt.args.in)
if !tt.wantErr(t, err, fmt.Sprintf("SendRoomStatus(%v, %v, %v)", tt.args.ctx, tt.args.forwarder, tt.args.in)) {
return
Expand Down