Skip to content

Commit

Permalink
*: Increase test timeout throughout
Browse files Browse the repository at this point in the history
This should make integration tests pass in CI.
  • Loading branch information
diamondburned committed Nov 4, 2023
1 parent 1e4c5c1 commit 2c2daec
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 170 deletions.
2 changes: 1 addition & 1 deletion 0-examples/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestExamples(t *testing.T) {
//
// TODO(diamondburned): find a way to detect that the bot is online. Maybe
// force all examples to print the current username?
const exampleRunDuration = 25 * time.Second
const exampleRunDuration = 60 * time.Second

buildDir, err := os.MkdirTemp("", "arikawa-examples")
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import (
)

const PerseveranceTime = 50 * time.Minute
const DefaultShardCount = 2

type Env struct {
BotToken string
ChannelID discord.ChannelID
VoiceChID discord.ChannelID
ShardCount int // default 3
ShardCount int
}

var (
Expand Down Expand Up @@ -67,7 +68,7 @@ func getEnv() {
return
}

shardCount := 2
shardCount := DefaultShardCount
if c, err := strconv.Atoi(os.Getenv("SHARD_COUNT")); err == nil {
shardCount = c
}
Expand Down
8 changes: 4 additions & 4 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (

func TestSession(t *testing.T) {
attempts := 1
timeout := 15 * time.Second
timeout := 45 * time.Second

if !testing.Short() {
attempts = 5
timeout = time.Minute // 5s-10s each reconnection
timeout = 8 * time.Minute
}

ctx, cancel := context.WithTimeout(context.Background(), timeout)
Expand Down Expand Up @@ -51,11 +51,11 @@ func TestSession(t *testing.T) {

func TestSessionConnect(t *testing.T) {
attempts := 1
timeout := 15 * time.Second
timeout := 45 * time.Second

if !testing.Short() {
attempts = 5
timeout = time.Minute // 5s-10s each reconnection
timeout = 8 * time.Minute
}

ctx, cancel := context.WithTimeout(context.Background(), timeout)
Expand Down
39 changes: 24 additions & 15 deletions session/shard/shard_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package shard
package shard_test

import (
"context"
Expand All @@ -8,6 +8,7 @@ import (
"github.com/diamondburned/arikawa/v3/gateway"
"github.com/diamondburned/arikawa/v3/internal/testenv"
"github.com/diamondburned/arikawa/v3/session"
"github.com/diamondburned/arikawa/v3/session/shard"
)

func TestSharding(t *testing.T) {
Expand All @@ -18,8 +19,8 @@ func TestSharding(t *testing.T) {

readyCh := make(chan *gateway.ReadyEvent)

m, err := NewIdentifiedManager(data, NewSessionShard(
func(m *Manager, s *session.Session) {
m, err := shard.NewIdentifiedManager(data, shard.NewSessionShard(
func(m *shard.Manager, s *session.Session) {
now := time.Now().Format(time.StampMilli)
t.Log(now, "initializing shard")

Expand All @@ -34,32 +35,40 @@ func TestSharding(t *testing.T) {
t.Fatal("failed to make shard manager:", err)
}

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
ctx, cancel := context.WithTimeout(
context.Background(),
2*time.Minute*time.Duration(env.ShardCount))
defer cancel()

openDone := make(chan struct{})
go func() {
// Timeout
defer close(openDone)
if err := m.Open(ctx); err != nil {
t.Error("failed to open:", err)
cancel()
}

t.Cleanup(func() {
if err := m.Close(); err != nil {
t.Error("failed to close:", err)
cancel()
}
})
}()
t.Cleanup(func() { m.Close() })

// Expect 4 Ready events.
shardLoop:
for i := 0; i < env.ShardCount; i++ {
select {
case ready := <-readyCh:
now := time.Now().Format(time.StampMilli)
t.Log(now, "shard", ready.Shard.ShardID(), "is ready out of", env.ShardCount)
case <-ctx.Done():
t.Fatal("test expired, got", i, "shards")
t.Error("test expired, got", i, "shards")
break shardLoop
}
}

select {
case <-openDone:
t.Log("all shards opened")
case <-ctx.Done():
t.Error("test expired")
}

if err := m.Close(); err != nil {
t.Error("failed to close:", err)
}
}
72 changes: 0 additions & 72 deletions state/state_shard_test.go

This file was deleted.

75 changes: 0 additions & 75 deletions utils/bot/ctx_shard_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion voice/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func testOpen(t *testing.T) *testState {
AddIntents(s)

func() {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
defer cancel()

if err := s.Open(ctx); err != nil {
Expand Down

0 comments on commit 2c2daec

Please sign in to comment.