Skip to content

Commit 88ddf12

Browse files
committed
test(model): Add a test to demonstrate issue with circular dependencies
Add a test to demonstrate that the default implementation of `DependencyHandler.areDependenciesEqual` runs into a stack overflow if there are cycles in the dependencies. Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
1 parent 1816af2 commit 88ddf12

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

model/src/test/kotlin/utils/DependencyGraphBuilderTest.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,32 @@ class DependencyGraphBuilderTest : WordSpec({
211211
graph.nodes shouldHaveSize 3
212212
}
213213

214+
"deal with recursive cycles in dependencies" {
215+
val scope = "CyclicScope"
216+
val id1 = Identifier("NPM::mlly:1.8.0")
217+
val id2 = Identifier("NPM::pkg-type:1.3.1")
218+
219+
val handler = object : DependencyHandler<Identifier> {
220+
override fun identifierFor(dependency: Identifier) = dependency
221+
222+
override fun dependenciesFor(dependency: Identifier) = when(dependency) {
223+
id1 -> listOf(id2)
224+
id2 -> listOf(id1)
225+
else -> emptyList()
226+
}
227+
228+
override fun linkageFor(dependency: Identifier) = PackageLinkage.STATIC
229+
230+
override fun createPackage(dependency: Identifier, issues: MutableCollection<Issue>) =
231+
Package.EMPTY.copy(id = dependency)
232+
}
233+
234+
DependencyGraphBuilder(handler)
235+
.addDependency(scope, id1)
236+
.addDependency(scope, id2)
237+
.build()
238+
}
239+
214240
"check for illegal references when building the graph" {
215241
val depLang = createDependency("org.apache.commons", "commons-lang3", "3.11")
216242
val depNoPkg = createDependency(NO_PACKAGE_NAMESPACE, "invalid", "1.2")

0 commit comments

Comments
 (0)