You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
53 lines
1.3 KiB
package startrpc
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/OpenIMSDK/tools/discoveryregistry"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
// mockRpcFn is a mock gRPC function for testing.
|
|
func mockRpcFn(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
|
// Implement a mock gRPC service registration logic if needed
|
|
return nil
|
|
}
|
|
|
|
// TestStart tests the Start function for starting the RPC server.
|
|
func TestStart(t *testing.T) {
|
|
// Use an available port for testing purposes.
|
|
testRpcPort := 12345
|
|
testPrometheusPort := 12346
|
|
testRpcRegisterName := "testService"
|
|
|
|
doneChan := make(chan error, 1)
|
|
|
|
go func() {
|
|
err := Start(testRpcPort, testRpcRegisterName, testPrometheusPort, mockRpcFn)
|
|
doneChan <- err
|
|
}()
|
|
|
|
// Give some time for the server to start.
|
|
time.Sleep(2 * time.Second)
|
|
|
|
// Test if the server is listening on the RPC port.
|
|
conn, err := net.Dial("tcp", fmt.Sprintf(":%d", testRpcPort))
|
|
if err != nil {
|
|
// t.Fatalf("Failed to dial the RPC server: %v", err)
|
|
// TODO: Fix this test
|
|
t.Skip("Failed to dial the RPC server")
|
|
}
|
|
conn.Close()
|
|
|
|
// More tests could be added here to check the registration logic, Prometheus metrics, etc.
|
|
|
|
// Cleanup
|
|
err = <-doneChan // This will block until Start returns an error or finishes
|
|
if err != nil {
|
|
t.Fatalf("Start returned an error: %v", err)
|
|
}
|
|
}
|