Skip to content

Commit

Permalink
fix session_test to use boundedWaitGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
aforge authored and or-else committed Jul 12, 2023
1 parent f89ca30 commit 7ce800d
Showing 1 changed file with 33 additions and 161 deletions.
194 changes: 33 additions & 161 deletions server/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ import (
"github.com/tinode/chat/server/store/types"
)

func test_makeSession(uid types.Uid) *Session {
return &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: newBoundedWaitGroup(1),
ver: 22,
}
}

func TestDispatchHello(t *testing.T) {
s := &Session{
send: make(chan any, 10),
Expand Down Expand Up @@ -211,13 +221,7 @@ func TestDispatchLogin(t *testing.T) {

func TestDispatchSubscribe(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -266,13 +270,7 @@ func TestDispatchSubscribe(t *testing.T) {

func TestDispatchAlreadySubscribed(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -300,13 +298,7 @@ func TestDispatchAlreadySubscribed(t *testing.T) {

func TestDispatchSubscribeJoinChannelFull(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -341,13 +333,7 @@ func TestDispatchSubscribeJoinChannelFull(t *testing.T) {

func TestDispatchLeave(t *testing.T) {

This comment has been minimized.

Copy link
@dilshansdoq

dilshansdoq Oct 20, 2023

This test fatals. @or-else
Session subs: expected to be empty, actual size: 1

This comment has been minimized.

Copy link
@aforge

aforge Oct 20, 2023

Contributor

Fixed in f760f85

uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -395,13 +381,7 @@ func TestDispatchLeave(t *testing.T) {

func TestDispatchLeaveUnsubMe(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand All @@ -428,13 +408,7 @@ func TestDispatchLeaveUnsubMe(t *testing.T) {

func TestDispatchLeaveUnknownTopic(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand All @@ -460,13 +434,7 @@ func TestDispatchLeaveUnknownTopic(t *testing.T) {

func TestDispatchLeaveUnsubFromUnknownTopic(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand All @@ -493,13 +461,7 @@ func TestDispatchLeaveUnsubFromUnknownTopic(t *testing.T) {

func TestDispatchPublish(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -549,13 +511,7 @@ func TestDispatchPublish(t *testing.T) {

func TestDispatchPublishBroadcastChannelFull(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -590,13 +546,7 @@ func TestDispatchPublishBroadcastChannelFull(t *testing.T) {

func TestDispatchPublishMissingSubcription(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -625,13 +575,7 @@ func TestDispatchPublishMissingSubcription(t *testing.T) {

func TestDispatchGet(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -676,13 +620,7 @@ func TestDispatchGet(t *testing.T) {

func TestDispatchGetMalformedWhat(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand All @@ -709,13 +647,7 @@ func TestDispatchGetMalformedWhat(t *testing.T) {

func TestDispatchGetMetaChannelFull(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -750,13 +682,7 @@ func TestDispatchGetMetaChannelFull(t *testing.T) {

func TestDispatchSet(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -808,13 +734,7 @@ func TestDispatchSet(t *testing.T) {

func TestDispatchSetMalformedWhat(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand All @@ -840,13 +760,7 @@ func TestDispatchSetMalformedWhat(t *testing.T) {

func TestDispatchSetMetaChannelFull(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -885,13 +799,7 @@ func TestDispatchSetMetaChannelFull(t *testing.T) {

func TestDispatchDelMsg(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -936,13 +844,7 @@ func TestDispatchDelMsg(t *testing.T) {

func TestDispatchDelMalformedWhat(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand All @@ -967,13 +869,7 @@ func TestDispatchDelMalformedWhat(t *testing.T) {

func TestDispatchDelMetaChanFull(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -1008,13 +904,7 @@ func TestDispatchDelMetaChanFull(t *testing.T) {

func TestDispatchDelUnsubscribedSession(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -1042,13 +932,7 @@ func TestDispatchDelUnsubscribedSession(t *testing.T) {

func TestDispatchNote(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -1100,13 +984,7 @@ func TestDispatchNote(t *testing.T) {

func TestDispatchNoteBroadcastChanFull(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down Expand Up @@ -1139,13 +1017,7 @@ func TestDispatchNoteBroadcastChanFull(t *testing.T) {

func TestDispatchNoteOnNonSubscribedTopic(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
ver: 15,
}
s := test_makeSession(uid)
wg := sync.WaitGroup{}
r := responses{}
wg.Add(1)
Expand Down

0 comments on commit 7ce800d

Please sign in to comment.