Skip to content
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
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ go_deps.from_file(go_mod = "//:go.mod")
use_repo(
go_deps,
"com_github_gogo_protobuf",
"com_github_stretchr_testify",
"com_github_uber_go_tally_v4",
"org_golang_google_grpc",
"org_golang_google_protobuf",
Expand Down
8 changes: 7 additions & 1 deletion gateway/controller/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@ go_test(
name = "controller_test",
srcs = ["ping_test.go", "land_test.go"],
embed = [":controller"],
deps = ["//gateway/protopb"],
deps = [
"//gateway/protopb",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@com_github_uber_go_tally_v4//:tally",
"@org_uber_go_zap//:zap",
],
)
14 changes: 4 additions & 10 deletions gateway/controller/land_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"context"
"testing"

"github.com/stretchr/testify/require"
pb "github.com/uber/submitqueue/gateway/protopb"
)

func TestNewLandController(t *testing.T) {
controller := NewLandController(nil, nil)
if controller == nil {
t.Fatal("NewLandController() returned nil")
}
require.NotNil(t, controller)
}

func TestLand_ReturnsSqid(t *testing.T) {
Expand All @@ -24,11 +23,6 @@ func TestLand_ReturnsSqid(t *testing.T) {
}
resp, err := controller.Land(ctx, req)

if err != nil {
t.Fatalf("Land() returned error: %v", err)
}

if resp.Sqid == "" {
t.Fatal("Expected sqid to be set, got empty string")
}
require.NoError(t, err)
require.NotEmpty(t, resp.Sqid)
}
54 changes: 14 additions & 40 deletions gateway/controller/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
pb "github.com/uber/submitqueue/gateway/protopb"
)

func TestNewPingController(t *testing.T) {
controller := NewPingController(nil, nil)
if controller == nil {
t.Fatal("NewPingController() returned nil")
}
require.NotNil(t, controller)
}

func TestPing_DefaultMessage(t *testing.T) {
Expand All @@ -22,13 +22,8 @@ func TestPing_DefaultMessage(t *testing.T) {
req := &pb.PingRequest{}
resp, err := controller.Ping(ctx, req)

if err != nil {
t.Fatalf("Ping() returned error: %v", err)
}

if resp.Message != "pong" {
t.Errorf("Expected message 'pong', got '%s'", resp.Message)
}
require.NoError(t, err)
assert.Equal(t, "pong", resp.Message)
}

func TestPing_CustomMessage(t *testing.T) {
Expand All @@ -50,13 +45,8 @@ func TestPing_CustomMessage(t *testing.T) {
req := &pb.PingRequest{Message: tc.input}
resp, err := controller.Ping(ctx, req)

if err != nil {
t.Fatalf("Ping() returned error: %v", err)
}

if resp.Message != tc.expected {
t.Errorf("Expected message '%s', got '%s'", tc.expected, resp.Message)
}
require.NoError(t, err)
assert.Equal(t, tc.expected, resp.Message)
})
}
}
Expand All @@ -68,13 +58,8 @@ func TestPing_ServiceName(t *testing.T) {
req := &pb.PingRequest{}
resp, err := controller.Ping(ctx, req)

if err != nil {
t.Fatalf("Ping() returned error: %v", err)
}

if resp.ServiceName != "gateway" {
t.Errorf("Expected service name 'gateway', got '%s'", resp.ServiceName)
}
require.NoError(t, err)
assert.Equal(t, "gateway", resp.ServiceName)
}

func TestPing_Timestamp(t *testing.T) {
Expand All @@ -86,13 +71,9 @@ func TestPing_Timestamp(t *testing.T) {
resp, err := controller.Ping(ctx, req)
after := time.Now().Unix()

if err != nil {
t.Fatalf("Ping() returned error: %v", err)
}

if resp.Timestamp < before || resp.Timestamp > after {
t.Errorf("Timestamp %d is not within expected range [%d, %d]", resp.Timestamp, before, after)
}
require.NoError(t, err)
assert.GreaterOrEqual(t, resp.Timestamp, before)
assert.LessOrEqual(t, resp.Timestamp, after)
}

func TestPing_Hostname(t *testing.T) {
Expand All @@ -102,13 +83,6 @@ func TestPing_Hostname(t *testing.T) {
req := &pb.PingRequest{}
resp, err := controller.Ping(ctx, req)

if err != nil {
t.Fatalf("Ping() returned error: %v", err)
}

// Hostname should be set (non-empty string)
// We don't check the exact value as it depends on the environment
if resp.Hostname == "" {
t.Error("Expected hostname to be set, got empty string")
}
require.NoError(t, err)
assert.NotEmpty(t, resp.Hostname)
}
2 changes: 2 additions & 0 deletions gateway/integration_tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ go_test(
],
deps = [
"//gateway/protopb",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@org_golang_google_grpc//:grpc",
"@org_golang_google_grpc//credentials/insecure",
],
Expand Down
26 changes: 8 additions & 18 deletions gateway/integration_tests/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
pb "github.com/uber/submitqueue/gateway/protopb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -24,9 +26,7 @@ func TestPingAPI(t *testing.T) {

// Wait for server to be ready
conn, err := waitForServer(t, addr, serverReadyTimeout)
if err != nil {
t.Fatalf("Gateway server not ready: %v", err)
}
require.NoError(t, err, "Gateway server not ready")
defer conn.Close()

client := pb.NewSubmitQueueGatewayClient(conn)
Expand All @@ -39,23 +39,13 @@ func TestPingAPI(t *testing.T) {
}

resp, err := client.Ping(ctx, req)
if err != nil {
t.Fatalf("Ping failed: %v", err)
}
require.NoError(t, err, "Ping failed")

// Validate response
if resp.Message == "" {
t.Error("Response message is empty")
}
if resp.ServiceName != "gateway" {
t.Errorf("Expected service name 'gateway', got '%s'", resp.ServiceName)
}
if resp.Timestamp == 0 {
t.Error("Timestamp is zero")
}
if resp.Hostname == "" {
t.Error("Hostname is empty")
}
assert.NotEmpty(t, resp.Message, "Response message should not be empty")
assert.Equal(t, "gateway", resp.ServiceName)
assert.NotZero(t, resp.Timestamp, "Timestamp should not be zero")
assert.NotEmpty(t, resp.Hostname, "Hostname should not be empty")

t.Logf("Gateway Ping test passed:")
t.Logf(" Message: %s", resp.Message)
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.24.5

require (
github.com/gogo/protobuf v1.3.2
github.com/stretchr/testify v1.9.0
github.com/uber-go/tally/v4 v4.1.17
go.uber.org/fx v1.22.0
go.uber.org/yarpc v1.81.0
Expand All @@ -16,12 +17,14 @@ require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/status v1.1.0 // indirect
github.com/golang/mock v1.7.0-rc.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
Expand All @@ -43,5 +46,6 @@ require (
golang.org/x/text v0.23.0 // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241230172942-26aa7a208def // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/tools v0.4.3 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
Expand All @@ -91,6 +93,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -283,6 +287,8 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ go_test(
"//gateway/protopb",
"//orchestrator/protopb",
"//speculator/protopb",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@org_golang_google_grpc//:grpc",
"@org_golang_google_grpc//credentials/insecure",
],
Expand Down
38 changes: 11 additions & 27 deletions integration_tests/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
gatewaypb "github.com/uber/submitqueue/gateway/protopb"
orchestratorpb "github.com/uber/submitqueue/orchestrator/protopb"
speculatorpb "github.com/uber/submitqueue/speculator/protopb"
Expand All @@ -27,68 +29,50 @@ func TestPingForAllServices(t *testing.T) {
t.Run("Gateway", func(t *testing.T) {
addr := getEnvOrDefault("GATEWAY_ADDR", "localhost:8081")
conn, err := waitForServer(t, addr, serverReadyTimeout)
if err != nil {
t.Fatalf("Gateway server not ready: %v", err)
}
require.NoError(t, err, "Gateway server not ready")
defer conn.Close()

client := gatewaypb.NewSubmitQueueGatewayClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()

resp, err := client.Ping(ctx, &gatewaypb.PingRequest{Message: "e2e test"})
if err != nil {
t.Fatalf("Gateway Ping failed: %v", err)
}
if resp.ServiceName != "gateway" {
t.Errorf("Expected service name 'gateway', got '%s'", resp.ServiceName)
}
require.NoError(t, err, "Gateway Ping failed")
assert.Equal(t, "gateway", resp.ServiceName)
t.Logf("Gateway is healthy: %s", resp.Message)
})

// Test Orchestrator
t.Run("Orchestrator", func(t *testing.T) {
addr := getEnvOrDefault("ORCHESTRATOR_ADDR", "localhost:8082")
conn, err := waitForServer(t, addr, serverReadyTimeout)
if err != nil {
t.Fatalf("Orchestrator server not ready: %v", err)
}
require.NoError(t, err, "Orchestrator server not ready")
defer conn.Close()

client := orchestratorpb.NewSubmitQueueOrchestratorClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()

resp, err := client.Ping(ctx, &orchestratorpb.PingRequest{Message: "e2e test"})
if err != nil {
t.Fatalf("Orchestrator Ping failed: %v", err)
}
if resp.ServiceName != "orchestrator" {
t.Errorf("Expected service name 'orchestrator', got '%s'", resp.ServiceName)
}
require.NoError(t, err, "Orchestrator Ping failed")
assert.Equal(t, "orchestrator", resp.ServiceName)
t.Logf("Orchestrator is healthy: %s", resp.Message)
})

// Test Speculator
t.Run("Speculator", func(t *testing.T) {
addr := getEnvOrDefault("SPECULATOR_ADDR", "localhost:8083")
conn, err := waitForServer(t, addr, serverReadyTimeout)
if err != nil {
t.Fatalf("Speculator server not ready: %v", err)
}
require.NoError(t, err, "Speculator server not ready")
defer conn.Close()

client := speculatorpb.NewSubmitQueueSpeculatorClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()

resp, err := client.Ping(ctx, &speculatorpb.PingRequest{Message: "e2e test"})
if err != nil {
t.Fatalf("Speculator Ping failed: %v", err)
}
if resp.ServiceName != "speculator" {
t.Errorf("Expected service name 'speculator', got '%s'", resp.ServiceName)
}
require.NoError(t, err, "Speculator Ping failed")
assert.Equal(t, "speculator", resp.ServiceName)
t.Logf("Speculator is healthy: %s", resp.Message)
})

Expand Down
8 changes: 7 additions & 1 deletion orchestrator/controller/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@ go_test(
name = "controller_test",
srcs = ["ping_test.go"],
embed = [":controller"],
deps = ["//orchestrator/protopb"],
deps = [
"//orchestrator/protopb",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@com_github_uber_go_tally_v4//:tally",
"@org_uber_go_zap//:zap",
],
)
Loading