mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-10 17:59:38 +08:00
fix: fix ci failed for tests
This commit is contained in:
parent
7f9cf8b922
commit
0f66c14299
@ -133,14 +133,10 @@ public class TestFixture<TEntryPoint> : IAsyncLifetime
|
||||
{
|
||||
CancellationTokenSource = new CancellationTokenSource();
|
||||
await StartTestContainerAsync();
|
||||
|
||||
await TestHarness.Start();
|
||||
}
|
||||
|
||||
public async Task DisposeAsync()
|
||||
{
|
||||
await TestHarness.Stop();
|
||||
|
||||
await StopTestContainerAsync();
|
||||
await _factory.DisposeAsync();
|
||||
await CancellationTokenSource.CancelAsync();
|
||||
@ -277,14 +273,11 @@ public class TestFixture<TEntryPoint> : IAsyncLifetime
|
||||
MongoDbTestContainer = TestContainers.MongoTestContainer();
|
||||
EventStoreDbTestContainer = TestContainers.EventStoreTestContainer();
|
||||
|
||||
await Task.WhenAll(
|
||||
MongoDbTestContainer.StartAsync(),
|
||||
PostgresTestcontainer.StartAsync(),
|
||||
PostgresPersistTestContainer.StartAsync(),
|
||||
EventStoreDbTestContainer.StartAsync()
|
||||
);
|
||||
|
||||
await MongoDbTestContainer.StartAsync();
|
||||
await PostgresTestcontainer.StartAsync();
|
||||
await PostgresPersistTestContainer.StartAsync();
|
||||
await RabbitMqTestContainer.StartAsync();
|
||||
await EventStoreDbTestContainer.StartAsync();
|
||||
}
|
||||
|
||||
private async Task StopTestContainerAsync()
|
||||
|
||||
@ -13,9 +13,12 @@ public static class GrpcClientExtensions
|
||||
public static IServiceCollection AddGrpcClients(this IServiceCollection services)
|
||||
{
|
||||
var grpcOptions = services.GetOptions<GrpcOptions>("Grpc");
|
||||
var resilienceOptions = services.GetOptions<HttpStandardResilienceOptions>(nameof(HttpStandardResilienceOptions));
|
||||
var resilienceOptions = services.GetOptions<HttpStandardResilienceOptions>(
|
||||
nameof(HttpStandardResilienceOptions)
|
||||
);
|
||||
|
||||
services.AddGrpcClient<FlightGrpcService.FlightGrpcServiceClient>(o =>
|
||||
services
|
||||
.AddGrpcClient<FlightGrpcService.FlightGrpcServiceClient>(o =>
|
||||
{
|
||||
o.Address = new Uri(grpcOptions.FlightAddress);
|
||||
})
|
||||
@ -25,54 +28,37 @@ public static class GrpcClientExtensions
|
||||
{
|
||||
var timeSpan = TimeSpan.FromMinutes(1);
|
||||
|
||||
options.AddRetry(
|
||||
new HttpRetryStrategyOptions
|
||||
{
|
||||
MaxRetryAttempts = 3,
|
||||
});
|
||||
options.AddRetry(new HttpRetryStrategyOptions { MaxRetryAttempts = 3 });
|
||||
|
||||
options.AddCircuitBreaker(
|
||||
new HttpCircuitBreakerStrategyOptions
|
||||
{
|
||||
SamplingDuration = timeSpan * 2,
|
||||
});
|
||||
new HttpCircuitBreakerStrategyOptions { SamplingDuration = timeSpan * 2 }
|
||||
);
|
||||
|
||||
options.AddTimeout(
|
||||
new HttpTimeoutStrategyOptions
|
||||
{
|
||||
Timeout = timeSpan * 3,
|
||||
});
|
||||
});
|
||||
options.AddTimeout(new HttpTimeoutStrategyOptions { Timeout = timeSpan * 3 });
|
||||
}
|
||||
);
|
||||
|
||||
services.AddGrpcClient<PassengerGrpcService.PassengerGrpcServiceClient>(o =>
|
||||
{
|
||||
o.Address = new Uri(grpcOptions.PassengerAddress);
|
||||
})
|
||||
.AddResilienceHandler(
|
||||
"grpc-passenger-resilience",
|
||||
options =>
|
||||
services
|
||||
.AddGrpcClient<PassengerGrpcService.PassengerGrpcServiceClient>(o =>
|
||||
{
|
||||
var timeSpan = TimeSpan.FromMinutes(1);
|
||||
o.Address = new Uri(grpcOptions.PassengerAddress);
|
||||
})
|
||||
.AddResilienceHandler(
|
||||
"grpc-passenger-resilience",
|
||||
options =>
|
||||
{
|
||||
var timeSpan = TimeSpan.FromMinutes(1);
|
||||
|
||||
options.AddRetry(
|
||||
new HttpRetryStrategyOptions
|
||||
{
|
||||
MaxRetryAttempts = 3,
|
||||
});
|
||||
options.AddRetry(new HttpRetryStrategyOptions { MaxRetryAttempts = 3 });
|
||||
|
||||
options.AddCircuitBreaker(
|
||||
new HttpCircuitBreakerStrategyOptions
|
||||
{
|
||||
SamplingDuration = timeSpan * 2,
|
||||
});
|
||||
options.AddCircuitBreaker(
|
||||
new HttpCircuitBreakerStrategyOptions { SamplingDuration = timeSpan * 2 }
|
||||
);
|
||||
|
||||
options.AddTimeout(
|
||||
new HttpTimeoutStrategyOptions
|
||||
{
|
||||
Timeout = timeSpan * 3,
|
||||
});
|
||||
});
|
||||
options.AddTimeout(new HttpTimeoutStrategyOptions { Timeout = timeSpan * 3 });
|
||||
}
|
||||
);
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,10 +19,8 @@ namespace Integration.Test.Booking.Features
|
||||
{
|
||||
public class CreateBookingTests : BookingIntegrationTestBase
|
||||
{
|
||||
public CreateBookingTests(TestReadFixture<Program, BookingReadDbContext> integrationTestFixture) : base(
|
||||
integrationTestFixture)
|
||||
{
|
||||
}
|
||||
public CreateBookingTests(TestReadFixture<Program, BookingReadDbContext> integrationTestFixture)
|
||||
: base(integrationTestFixture) { }
|
||||
|
||||
protected override void RegisterTestsServices(IServiceCollection services)
|
||||
{
|
||||
@ -45,41 +43,76 @@ namespace Integration.Test.Booking.Features
|
||||
(await Fixture.WaitForPublishing<BookingCreated>()).Should().Be(true);
|
||||
}
|
||||
|
||||
|
||||
private void MockPassengerGrpcServices(IServiceCollection services)
|
||||
{
|
||||
services.Replace(ServiceDescriptor.Singleton(x =>
|
||||
{
|
||||
var mockPassenger = Substitute.For<PassengerGrpcService.PassengerGrpcServiceClient>();
|
||||
services.Replace(
|
||||
ServiceDescriptor.Singleton(x =>
|
||||
{
|
||||
var mockPassenger = Substitute.For<PassengerGrpcService.PassengerGrpcServiceClient>();
|
||||
|
||||
mockPassenger.GetByIdAsync(Arg.Any<Passenger.GetByIdRequest>())
|
||||
.Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakePassengerResponse.Generate()),
|
||||
Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }));
|
||||
mockPassenger
|
||||
.GetByIdAsync(Arg.Any<Passenger.GetByIdRequest>())
|
||||
.Returns(
|
||||
TestCalls.AsyncUnaryCall(
|
||||
Task.FromResult(FakePassengerResponse.Generate()),
|
||||
Task.FromResult(new Metadata()),
|
||||
() => Status.DefaultSuccess,
|
||||
() => new Metadata(),
|
||||
() => { }
|
||||
)
|
||||
);
|
||||
|
||||
return mockPassenger;
|
||||
}));
|
||||
return mockPassenger;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private void MockFlightGrpcServices(IServiceCollection services)
|
||||
{
|
||||
services.Replace(ServiceDescriptor.Singleton(x =>
|
||||
{
|
||||
var mockFlight = Substitute.For<FlightGrpcService.FlightGrpcServiceClient>();
|
||||
services.Replace(
|
||||
ServiceDescriptor.Singleton(x =>
|
||||
{
|
||||
var mockFlight = Substitute.For<FlightGrpcService.FlightGrpcServiceClient>();
|
||||
|
||||
mockFlight.GetByIdAsync(Arg.Any<GetByIdRequest>())
|
||||
.Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeFlightResponse.Generate()),
|
||||
Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }));
|
||||
mockFlight
|
||||
.GetByIdAsync(Arg.Any<GetByIdRequest>())
|
||||
.Returns(
|
||||
TestCalls.AsyncUnaryCall(
|
||||
Task.FromResult(FakeFlightResponse.Generate()),
|
||||
Task.FromResult(new Metadata()),
|
||||
() => Status.DefaultSuccess,
|
||||
() => new Metadata(),
|
||||
() => { }
|
||||
)
|
||||
);
|
||||
|
||||
mockFlight.GetAvailableSeatsAsync(Arg.Any<GetAvailableSeatsRequest>())
|
||||
.Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeGetAvailableSeatsResponse.Generate()),
|
||||
Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }));
|
||||
mockFlight
|
||||
.GetAvailableSeatsAsync(Arg.Any<GetAvailableSeatsRequest>())
|
||||
.Returns(
|
||||
TestCalls.AsyncUnaryCall(
|
||||
Task.FromResult(FakeGetAvailableSeatsResponse.Generate()),
|
||||
Task.FromResult(new Metadata()),
|
||||
() => Status.DefaultSuccess,
|
||||
() => new Metadata(),
|
||||
() => { }
|
||||
)
|
||||
);
|
||||
|
||||
mockFlight.ReserveSeatAsync(Arg.Any<ReserveSeatRequest>())
|
||||
.Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeReserveSeatResponse.Generate()),
|
||||
Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }));
|
||||
mockFlight
|
||||
.ReserveSeatAsync(Arg.Any<ReserveSeatRequest>())
|
||||
.Returns(
|
||||
TestCalls.AsyncUnaryCall(
|
||||
Task.FromResult(FakeReserveSeatResponse.Generate()),
|
||||
Task.FromResult(new Metadata()),
|
||||
() => Status.DefaultSuccess,
|
||||
() => new Metadata(),
|
||||
() => { }
|
||||
)
|
||||
);
|
||||
|
||||
return mockFlight;
|
||||
}));
|
||||
return mockFlight;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
using Booking.Api;
|
||||
using Booking.Data;
|
||||
using BuildingBlocks.TestBase;
|
||||
using Xunit;
|
||||
@ -8,13 +7,12 @@ namespace Integration.Test;
|
||||
[Collection(IntegrationTestCollection.Name)]
|
||||
public class BookingIntegrationTestBase : TestReadBase<Program, BookingReadDbContext>
|
||||
{
|
||||
public BookingIntegrationTestBase(TestReadFixture<Program, BookingReadDbContext> integrationTestFixture) : base(integrationTestFixture)
|
||||
{
|
||||
}
|
||||
public BookingIntegrationTestBase(TestReadFixture<Program, BookingReadDbContext> integrationTestFixture)
|
||||
: base(integrationTestFixture) { }
|
||||
}
|
||||
|
||||
[CollectionDefinition(Name)]
|
||||
public class IntegrationTestCollection : ICollectionFixture<TestReadFixture<Program, BookingReadDbContext>>
|
||||
{
|
||||
public const string Name = "Booking Integration Test";
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user