-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #993 from golemfactory/feature/JST-991/destroy-exe…
…-unit Creation of exe-unit during resource-rental startup
- Loading branch information
Showing
2 changed files
with
103 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { imock, instance, mock, reset, when, verify, _ } from "@johanblumenberg/ts-mockito"; | ||
import { Agreement, MarketModule } from "../market"; | ||
import { StorageProvider } from "../shared/storage"; | ||
import { AgreementPaymentProcess } from "../payment/agreement_payment_process"; | ||
import { ResourceRental, ResourceRentalOptions } from "."; | ||
import { ActivityModule, ExeUnit } from "../activity"; | ||
import { Logger } from "../shared/utils"; | ||
|
||
const mockAgreement = mock(Agreement); | ||
const mockStorageProvider = imock<StorageProvider>(); | ||
const mockPaymentProcess = mock(AgreementPaymentProcess); | ||
const mockMarketModule = imock<MarketModule>(); | ||
const mockActivityModule = imock<ActivityModule>(); | ||
const mockLogger = imock<Logger>(); | ||
const mockResourceRentalOptions = imock<ResourceRentalOptions>(); | ||
|
||
let resourceRental: ResourceRental; | ||
|
||
beforeEach(() => { | ||
reset(mockAgreement); | ||
reset(mockStorageProvider); | ||
reset(mockPaymentProcess); | ||
reset(mockMarketModule); | ||
reset(mockActivityModule); | ||
reset(mockLogger); | ||
reset(mockResourceRentalOptions); | ||
when(mockActivityModule.createExeUnit(_, _)).thenResolve(instance(mock(ExeUnit))); | ||
resourceRental = new ResourceRental( | ||
instance(mockAgreement), | ||
instance(mockStorageProvider), | ||
instance(mockPaymentProcess), | ||
instance(mockMarketModule), | ||
instance(mockActivityModule), | ||
instance(mockLogger), | ||
instance(mockResourceRentalOptions), | ||
); | ||
}); | ||
|
||
describe("ResourceRental", () => { | ||
describe("ExeUnit", () => { | ||
it("should create an exe unit on startup and use it later", async () => { | ||
expect(resourceRental["currentExeUnit"]).toBeDefined(); | ||
verify(mockActivityModule.createExeUnit(_, _)).once(); | ||
await resourceRental.getExeUnit(); | ||
verify(mockActivityModule.createExeUnit(_, _)).once(); | ||
}); | ||
|
||
it("should reuse the same promise if called multiple times", async () => { | ||
expect(resourceRental["currentExeUnit"]).toBeDefined(); | ||
const promise1 = resourceRental.getExeUnit(); | ||
const promise2 = resourceRental.getExeUnit(); | ||
const promise3 = resourceRental.getExeUnit(); | ||
await Promise.all([promise1, promise2, promise3]); | ||
verify(mockActivityModule.createExeUnit(_, _)).once(); | ||
}); | ||
|
||
it("should reuse the same promise if called multiple time after destroy exe-unit created on strtup", async () => { | ||
expect(resourceRental["currentExeUnit"]).toBeDefined(); | ||
await resourceRental.destroyExeUnit(); | ||
const promise1 = resourceRental.getExeUnit(); | ||
const promise2 = resourceRental.getExeUnit(); | ||
const promise3 = resourceRental.getExeUnit(); | ||
expect(resourceRental["exeUnitPromise"]).toBeDefined(); | ||
await Promise.all([promise1, promise2, promise3]); | ||
verify(mockActivityModule.createExeUnit(_, _)).twice(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters