Defer registration of singletons and pre-singletons in TestContext
In preparation for allowing the TestContext to enforce an ordering on the registration of singletons and pre-singletons in the same way as it does for mutators this defers the registration of them into the underlying Context. Bug: 181953909 Test: m nothing Change-Id: I2d9652122bb6387b6b47ca4761e811885d15c2b6
This commit is contained in:
parent
281deb2c6e
commit
d182fb3907
1 changed files with 10 additions and 2 deletions
|
@ -98,6 +98,9 @@ type TestContext struct {
|
|||
bp2buildPreArch, bp2buildDeps, bp2buildMutators []RegisterMutatorFunc
|
||||
NameResolver *NameResolver
|
||||
|
||||
// The list of pre-singletons and singletons registered for the test.
|
||||
preSingletons, singletons sortableComponents
|
||||
|
||||
// The order in which the mutators will be run in this test context; for debugging.
|
||||
mutatorOrder []string
|
||||
}
|
||||
|
@ -343,13 +346,18 @@ func globallyRegisteredComponentsOrder() *registrationSorter {
|
|||
func (ctx *TestContext) Register() {
|
||||
globalOrder := globallyRegisteredComponentsOrder()
|
||||
|
||||
ctx.preSingletons.registerAll(ctx.Context)
|
||||
|
||||
mutators := collateRegisteredMutators(ctx.preArch, ctx.preDeps, ctx.postDeps, ctx.finalDeps)
|
||||
// Ensure that the mutators used in the test are in the same order as they are used at runtime.
|
||||
globalOrder.mutatorOrder.enforceOrdering(mutators)
|
||||
mutators.registerAll(ctx.Context)
|
||||
|
||||
// Register the env singleton with this context before sorting.
|
||||
ctx.RegisterSingletonType("env", EnvSingleton)
|
||||
|
||||
ctx.singletons.registerAll(ctx.Context)
|
||||
|
||||
// Save the mutator order away to make it easy to access while debugging.
|
||||
ctx.mutatorOrder = globalOrder.mutatorOrder.namesInOrder
|
||||
}
|
||||
|
@ -382,11 +390,11 @@ func (ctx *TestContext) RegisterSingletonModuleType(name string, factory Singlet
|
|||
}
|
||||
|
||||
func (ctx *TestContext) RegisterSingletonType(name string, factory SingletonFactory) {
|
||||
ctx.Context.RegisterSingletonType(name, SingletonFactoryAdaptor(ctx.Context, factory))
|
||||
ctx.singletons = append(ctx.singletons, newSingleton(name, factory))
|
||||
}
|
||||
|
||||
func (ctx *TestContext) RegisterPreSingletonType(name string, factory SingletonFactory) {
|
||||
ctx.Context.RegisterPreSingletonType(name, SingletonFactoryAdaptor(ctx.Context, factory))
|
||||
ctx.preSingletons = append(ctx.preSingletons, newPreSingleton(name, factory))
|
||||
}
|
||||
|
||||
func (ctx *TestContext) ModuleForTests(name, variant string) TestingModule {
|
||||
|
|
Loading…
Reference in a new issue