Skip to content

Commit

Permalink
Fix/multiple failing components (#761)
Browse files Browse the repository at this point in the history
* Create a testbench to verify code is currently not working so we can apply a fix and have a working testbench later

* Fix code & improve testbench

* Update CHANGELOG.md

* Change implementation to use zipWithIndex
  • Loading branch information
Grifs authored Aug 13, 2024
1 parent 205f395 commit c8ee12f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ TODO add summary

* `viash ns exec`: Fix "relative fields" outputting absolute paths (PR# 737). Additionally, improve path resolution when using the `--src` argument.

* `viash ns`: Fix viash tripping over its toes when it encounters multiple failed configs (PR #761). A dummy config was used as a placeholder, but it always used the name `failed`, so duplicate config names were generated, which we check for nowadays.

* `bashwrapper`: Fix an issue where running `viash test` which builds the test docker container would ignore test failures but subsequential runs would work correctly (PR #754).

# Viash 0.9.0-RC6 (2024-06-17): Hotfix for docker image name generation
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/io/viash/config/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ object Config extends Logging {
attrs.isRegularFile
})

val allConfigs = scriptFiles.map { file =>
val allConfigs = scriptFiles.zipWithIndex.map { case (file, index) =>
try {
val rmos = new ReplayableMultiOutputStream()

Expand Down Expand Up @@ -822,7 +822,7 @@ object Config extends Logging {
} catch {
case _: Exception =>
error(s"Reading file '$file' failed")
AppliedConfig(Config("failed"), None, Nil, Some(BuildStatus.ParseError))
AppliedConfig(Config(s"failed_$index"), None, Nil, Some(BuildStatus.ParseError))
}
}

Expand Down
41 changes: 41 additions & 0 deletions src/test/scala/io/viash/config/ConfigTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ import io.viash.helpers.data_structures._
import io.viash.helpers.Logger
import io.viash.engines.NativeEngine
import io.viash.runners.ExecutableRunner
import io.viash.helpers.IO
import io.viash.helpers.status

class ConfigTest extends AnyFunSuite with BeforeAndAfterAll {
Logger.UseColorOverride.value = Some(false)

private val temporaryFolder = IO.makeTemp(s"viash_${this.getClass.getName}_")
private val tempFolStr = temporaryFolder.toString

private val nsPath = getClass.getResource("/testns/").getPath

val infoJson = Yaml("""
|foo:
| bar:
Expand Down Expand Up @@ -94,5 +102,38 @@ class ConfigTest extends AnyFunSuite with BeforeAndAfterAll {
assert(conf.findRunners(Some("executable")) == List(ExecutableRunner("executable")))
}

test("Can find and read multiple sources with default testns components") {
val tempFolder = temporaryFolder.resolve("test1")
Files.createDirectory(tempFolder)
IO.copyFolder(nsPath, tempFolder.toString())

val configs = Config.readConfigs(tempFolder.toString())

assert(configs.length == 7)
assert(configs.filter(_.status == None).length == 5)
assert(configs.filter(_.status == Some(status.Disabled)).length == 1, "Expect 1 disabled component")
assert(configs.filter(_.status == Some(status.ParseError)).length == 1, "Expect 1 failed component")
}

test("Can find and read multiple sources with multiple failing components") {
val tempFolder = temporaryFolder.resolve("test2")
Files.createDirectory(tempFolder)
IO.copyFolder(nsPath, tempFolder.toString())

Files.createDirectories(tempFolder.resolve("src/ns_error2"))
IO.write("this is an invalid config", tempFolder.resolve("src/ns_error2/invalid_config.vsh.yaml"))

val configs = Config.readConfigs(tempFolder.toString())

assert(configs.length == 8)
assert(configs.filter(_.status == None).length == 5)
assert(configs.filter(_.status == Some(status.Disabled)).length == 1, "Expect 1 disabled component")
assert(configs.filter(_.status == Some(status.ParseError)).length == 2, "Expect 2 failed component")
}

// TODO: expand functionality tests

override def afterAll(): Unit = {
IO.deleteRecursively(temporaryFolder)
}
}

0 comments on commit c8ee12f

Please sign in to comment.