277 lines
7.8 KiB
Go
277 lines
7.8 KiB
Go
package temporal
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
// TestWorkflowGRPCImpl_StartWorkflowExecution tests the gRPC StartWorkflowExecution
|
||
|
|
func TestWorkflowGRPCImpl_StartWorkflowExecution(t *testing.T) {
|
||
|
|
grpcClient, err := NewGRPCClient("localhost:7233")
|
||
|
|
if err != nil {
|
||
|
|
t.Skipf("Skipping: Temporal server not available at localhost:7233: %v", err)
|
||
|
|
}
|
||
|
|
defer grpcClient.Close()
|
||
|
|
|
||
|
|
impl := NewWorkflowGRPCImpl(grpcClient)
|
||
|
|
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||
|
|
defer cancel()
|
||
|
|
|
||
|
|
result, err := impl.StartWorkflowExecution(
|
||
|
|
ctx,
|
||
|
|
"default",
|
||
|
|
"test_workflow_"+t.Name(),
|
||
|
|
"TestWorkflow",
|
||
|
|
"default",
|
||
|
|
map[string]interface{}{"test": "data"},
|
||
|
|
)
|
||
|
|
|
||
|
|
// If Temporal server is running, we expect success
|
||
|
|
if err == nil {
|
||
|
|
if result["workflow_id"] != "test_workflow_"+t.Name() {
|
||
|
|
t.Errorf("Expected workflow_id %s, got %v", t.Name(), result["workflow_id"])
|
||
|
|
}
|
||
|
|
if result["run_id"] == nil {
|
||
|
|
t.Error("Expected run_id in response")
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
// If server is not available, that's okay for this test
|
||
|
|
t.Logf("Temporal server not available: %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestWorkflowGRPCImpl_DescribeWorkflowExecution tests the gRPC DescribeWorkflowExecution
|
||
|
|
func TestWorkflowGRPCImpl_DescribeWorkflowExecution(t *testing.T) {
|
||
|
|
grpcClient, err := NewGRPCClient("localhost:7233")
|
||
|
|
if err != nil {
|
||
|
|
t.Skipf("Skipping: Temporal server not available: %v", err)
|
||
|
|
}
|
||
|
|
defer grpcClient.Close()
|
||
|
|
|
||
|
|
impl := NewWorkflowGRPCImpl(grpcClient)
|
||
|
|
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||
|
|
defer cancel()
|
||
|
|
|
||
|
|
result, err := impl.DescribeWorkflowExecution(ctx, "default", "test_id", "run_id")
|
||
|
|
|
||
|
|
// If Temporal server is running, we expect either success or a valid error
|
||
|
|
if err == nil {
|
||
|
|
if result["workflow_id"] == nil {
|
||
|
|
t.Error("Expected workflow_id in response")
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
// If server is not available or workflow not found, that's okay for this test
|
||
|
|
t.Logf("gRPC call result: %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestWorkflowGRPCImpl_TerminateWorkflowExecution tests termination
|
||
|
|
func TestWorkflowGRPCImpl_TerminateWorkflowExecution(t *testing.T) {
|
||
|
|
grpcClient, err := NewGRPCClient("localhost:7233")
|
||
|
|
if err != nil {
|
||
|
|
t.Skipf("Skipping: Temporal server not available: %v", err)
|
||
|
|
}
|
||
|
|
defer grpcClient.Close()
|
||
|
|
|
||
|
|
impl := NewWorkflowGRPCImpl(grpcClient)
|
||
|
|
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||
|
|
defer cancel()
|
||
|
|
|
||
|
|
result, err := impl.TerminateWorkflowExecution(ctx, "default", "test_id", "run_id", "test termination")
|
||
|
|
|
||
|
|
if err == nil {
|
||
|
|
if result["status"] != "TERMINATED" {
|
||
|
|
t.Errorf("Expected status TERMINATED, got %v", result["status"])
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
t.Logf("gRPC call result (expected if server unavailable): %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestWorkflowGRPCImpl_CancelWorkflowExecution tests cancellation
|
||
|
|
func TestWorkflowGRPCImpl_CancelWorkflowExecution(t *testing.T) {
|
||
|
|
grpcClient, err := NewGRPCClient("localhost:7233")
|
||
|
|
if err != nil {
|
||
|
|
t.Skipf("Skipping: Temporal server not available: %v", err)
|
||
|
|
}
|
||
|
|
defer grpcClient.Close()
|
||
|
|
|
||
|
|
impl := NewWorkflowGRPCImpl(grpcClient)
|
||
|
|
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||
|
|
defer cancel()
|
||
|
|
|
||
|
|
result, err := impl.CancelWorkflowExecution(ctx, "default", "test_id", "run_id")
|
||
|
|
|
||
|
|
if err == nil {
|
||
|
|
if result["status"] != "CANCEL_REQUESTED" {
|
||
|
|
t.Errorf("Expected status CANCEL_REQUESTED, got %v", result["status"])
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
t.Logf("gRPC call result (expected if server unavailable): %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestWorkflowGRPCImpl_SignalWorkflowExecution tests signaling
|
||
|
|
func TestWorkflowGRPCImpl_SignalWorkflowExecution(t *testing.T) {
|
||
|
|
grpcClient, err := NewGRPCClient("localhost:7233")
|
||
|
|
if err != nil {
|
||
|
|
t.Skipf("Skipping: Temporal server not available: %v", err)
|
||
|
|
}
|
||
|
|
defer grpcClient.Close()
|
||
|
|
|
||
|
|
impl := NewWorkflowGRPCImpl(grpcClient)
|
||
|
|
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||
|
|
defer cancel()
|
||
|
|
|
||
|
|
result, err := impl.SignalWorkflowExecution(
|
||
|
|
ctx,
|
||
|
|
"default",
|
||
|
|
"test_id",
|
||
|
|
"run_id",
|
||
|
|
"test_signal",
|
||
|
|
map[string]interface{}{"data": "value"},
|
||
|
|
)
|
||
|
|
|
||
|
|
if err == nil {
|
||
|
|
if result["signal_name"] != "test_signal" {
|
||
|
|
t.Errorf("Expected signal_name test_signal, got %v", result["signal_name"])
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
t.Logf("gRPC call result (expected if server unavailable): %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestWorkflowGRPCImpl_QueryWorkflowExecution tests querying
|
||
|
|
func TestWorkflowGRPCImpl_QueryWorkflowExecution(t *testing.T) {
|
||
|
|
grpcClient, err := NewGRPCClient("localhost:7233")
|
||
|
|
if err != nil {
|
||
|
|
t.Skipf("Skipping: Temporal server not available: %v", err)
|
||
|
|
}
|
||
|
|
defer grpcClient.Close()
|
||
|
|
|
||
|
|
impl := NewWorkflowGRPCImpl(grpcClient)
|
||
|
|
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||
|
|
defer cancel()
|
||
|
|
|
||
|
|
result, err := impl.QueryWorkflowExecution(ctx, "default", "test_id", "run_id", "test_query")
|
||
|
|
|
||
|
|
if err == nil {
|
||
|
|
if result["query_type"] != "test_query" {
|
||
|
|
t.Errorf("Expected query_type test_query, got %v", result["query_type"])
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
t.Logf("gRPC call result (expected if server unavailable): %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestWorkflowGRPCImpl_ListWorkflowExecutions tests listing
|
||
|
|
func TestWorkflowGRPCImpl_ListWorkflowExecutions(t *testing.T) {
|
||
|
|
grpcClient, err := NewGRPCClient("localhost:7233")
|
||
|
|
if err != nil {
|
||
|
|
t.Skipf("Skipping: Temporal server not available: %v", err)
|
||
|
|
}
|
||
|
|
defer grpcClient.Close()
|
||
|
|
|
||
|
|
impl := NewWorkflowGRPCImpl(grpcClient)
|
||
|
|
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||
|
|
defer cancel()
|
||
|
|
|
||
|
|
result, err := impl.ListWorkflowExecutions(ctx, "default", 10)
|
||
|
|
|
||
|
|
if err == nil {
|
||
|
|
if result["count"] == nil {
|
||
|
|
t.Error("Expected count in response")
|
||
|
|
}
|
||
|
|
if result["executions"] == nil {
|
||
|
|
t.Error("Expected executions in response")
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
t.Logf("gRPC call result (expected if server unavailable): %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestWorkflowGRPCImpl_GetWorkflowExecutionHistory tests history retrieval
|
||
|
|
func TestWorkflowGRPCImpl_GetWorkflowExecutionHistory(t *testing.T) {
|
||
|
|
grpcClient, err := NewGRPCClient("localhost:7233")
|
||
|
|
if err != nil {
|
||
|
|
t.Skipf("Skipping: Temporal server not available: %v", err)
|
||
|
|
}
|
||
|
|
defer grpcClient.Close()
|
||
|
|
|
||
|
|
impl := NewWorkflowGRPCImpl(grpcClient)
|
||
|
|
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||
|
|
defer cancel()
|
||
|
|
|
||
|
|
result, err := impl.GetWorkflowExecutionHistory(ctx, "default", "test_id", "run_id")
|
||
|
|
|
||
|
|
if err == nil {
|
||
|
|
if result["events"] == nil {
|
||
|
|
t.Error("Expected events in response")
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
t.Logf("gRPC call result (expected if server unavailable): %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestSearchAttributesGRPCImpl_ListSearchAttributes tests search attributes listing
|
||
|
|
func TestSearchAttributesGRPCImpl_ListSearchAttributes(t *testing.T) {
|
||
|
|
grpcClient, err := NewGRPCClient("localhost:7233")
|
||
|
|
if err != nil {
|
||
|
|
t.Skipf("Skipping: Temporal server not available: %v", err)
|
||
|
|
}
|
||
|
|
defer grpcClient.Close()
|
||
|
|
|
||
|
|
impl := NewSearchAttributesGRPCImpl(grpcClient)
|
||
|
|
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||
|
|
defer cancel()
|
||
|
|
|
||
|
|
result, err := impl.ListSearchAttributes(ctx)
|
||
|
|
|
||
|
|
if err == nil {
|
||
|
|
if result["count"] == nil {
|
||
|
|
t.Error("Expected count in response")
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
t.Logf("gRPC call result (expected if server unavailable): %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestGRPCClient_HealthCheck tests the health check
|
||
|
|
func TestGRPCClient_HealthCheck(t *testing.T) {
|
||
|
|
grpcClient, err := NewGRPCClient("localhost:7233")
|
||
|
|
if err != nil {
|
||
|
|
t.Skipf("Skipping: Cannot connect to Temporal server: %v", err)
|
||
|
|
}
|
||
|
|
defer grpcClient.Close()
|
||
|
|
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||
|
|
defer cancel()
|
||
|
|
|
||
|
|
err = grpcClient.HealthCheck(ctx)
|
||
|
|
|
||
|
|
if err != nil {
|
||
|
|
t.Logf("Health check failed (expected if Temporal server not running): %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestGRPCClient_ConnectionFailure tests connection error handling
|
||
|
|
func TestGRPCClient_ConnectionFailure(t *testing.T) {
|
||
|
|
// Try to connect to non-existent server
|
||
|
|
grpcClient, err := NewGRPCClient("localhost:9999")
|
||
|
|
|
||
|
|
// Connection should be created but fail on first call
|
||
|
|
if grpcClient == nil && err != nil {
|
||
|
|
t.Logf("Expected connection attempt: %v", err)
|
||
|
|
}
|
||
|
|
}
|