Search code examples
unit-testinggoubuntugithub-actions

Too many open files error when running go test in github actions and ubuntu


We have buitl a test suite that always worked on local ubuntu machines and on ubuntu machines on github actions. Since the latest additions of unit tests the number of unit tests of one package grew quite substantially and it starts to fail with a too many open files error message:

{"Time":"2021-10-22T13:24:15.784106437Z","Action":"output","Package":"github.com/MyCompany/Product/src/interface/service/user","Test":"Test_userService_MethodTest/Case_1","Output":"2021/10/22 13:24:15 too many open files\n"}

Two strange things appear: On Windows there is no such problem. And if I comment out half of the unit tests in the package mentioned in the error it does not happen either.

The number of unit tests in the affected package is 245 for now and it approximately stops working at around or so.


Solution

  • In our test setup we had the config injected by a separate viper instance for each subtest which opened some files everytime. Centrally defining one viper instance and then pass the config down into the tests did the trick.