# tests failing in core on Windows

**URL:** <https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471>\
**Category:** Platform\
**Created:** [July 17, 2020, 9:03am UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471 "2020-07-17T09:03:37Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![teleivo](https://talk.openmrs.org/user_avatar/talk.openmrs.org/teleivo/32/2015_2.png) [@teleivo](https://talk.openmrs.org/u/teleivo)\
**Post date:** [July 17, 2020, 12:13pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/21 "2020-07-17T12:13:46Z")

</div>

its pretty clear to me now from the error message

```auto
Suppressed: java.nio.file.FileSystemException: C:\Users\Cliff\AppData\Local\Temp\junit1581269591057766963\TestingComplexObsSaving_9064e534-7f4b-45be-b266-a78bd131b7fb.mp3: The process cannot access the file because it is being used by another process.

```

that something is holding on to the file/stream in these 2 tests that are failing. So either its our test that needs to close them or the implementation has a bug that hasn’t been detected. I will investigate further. I will ask @gcliff to try again as soon as I have changed things. Thank you for letting us know 🙂

---

<div class="post-metadata">

**Author:** ![gcliff](https://talk.openmrs.org/user_avatar/talk.openmrs.org/gcliff/32/8783_2.png) [@gcliff](https://talk.openmrs.org/u/gcliff)\
**Post date:** [July 17, 2020, 12:17pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/22 "2020-07-17T12:17:07Z")

</div>

thanks @teleivo for your investigations on this 🤠

---

<div class="post-metadata">

**Author:** ![teleivo](https://talk.openmrs.org/user_avatar/talk.openmrs.org/teleivo/32/2015_2.png) [@teleivo](https://talk.openmrs.org/u/teleivo)\
**Post date:** [July 17, 2020, 12:40pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/23 "2020-07-17T12:40:42Z")

</div>

@gcliff please pull and try again. I adapted the tests to close the input streams it creates. I hope this fixes the tests on Windows 🤞 let us know

---

<div class="post-metadata">

**Author:** ![gcliff](https://talk.openmrs.org/user_avatar/talk.openmrs.org/gcliff/32/8783_2.png) [@gcliff](https://talk.openmrs.org/u/gcliff)\
**Post date:** [July 17, 2020, 1:04pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/24 "2020-07-17T13:04:33Z")

</div>

@teleivo its still misbehaving [https://pastebin.com/gqJQ61Nv](https://pastebin.com/gqJQ61Nv)

---

<div class="post-metadata">

**Author:** ![teleivo](https://talk.openmrs.org/user_avatar/talk.openmrs.org/teleivo/32/2015_2.png) [@teleivo](https://talk.openmrs.org/u/teleivo)\
**Post date:** [July 17, 2020, 1:09pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/25 "2020-07-17T13:09:21Z")

</div>

Out of curiosity whats in the temp dir that cannot be deleted by JUnit? The one it shows when the test fails `C:\Users\Cliff\AppData\Local\Temp\junit3772331837415344270` And is there any difference when you run this from your IDE?

---

<div class="post-metadata">

**Author:** ![teleivo](https://talk.openmrs.org/user_avatar/talk.openmrs.org/teleivo/32/2015_2.png) [@teleivo](https://talk.openmrs.org/u/teleivo)\
**Post date:** [July 17, 2020, 1:13pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/26 "2020-07-17T13:13:59Z")

</div>

and @gcliff please replace

> <https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/obs/handler/BinaryStreamHandler.java#L117>

with `FileCopyUtils.copy(in, out);` with import `import org.springframework.util.FileCopyUtils;` The FileCopyUtils from Spring closes the in and outputstream.

I would be interested if that is solving it. Then we should have closed all stream/handles on the files JUnit wants to delete. At least that is my hope 😅

---

<div class="post-metadata">

**Author:** ![teleivo](https://talk.openmrs.org/user_avatar/talk.openmrs.org/teleivo/32/2015_2.png) [@teleivo](https://talk.openmrs.org/u/teleivo)\
**Post date:** [July 17, 2020, 1:46pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/27 "2020-07-17T13:46:08Z")

</div>

Am interested to know if my suggestion changed anything for you @gcliff

What I am struggling to understand is

> <https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/obs/handler/MediaHandler.java#L105>

and

> <https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/obs/handler/BinaryStreamHandler.java#L114>

since the `OpenmrsUtil.copyFile(in, out);` does not close the InputStream I believe the saveObs should then close them.

@dkayiwa what is your take on this?

---

<div class="post-metadata">

**Author:** ![gcliff](https://talk.openmrs.org/user_avatar/talk.openmrs.org/gcliff/32/8783_2.png) [@gcliff](https://talk.openmrs.org/u/gcliff)\
**Post date:** [July 17, 2020, 1:48pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/28 "2020-07-17T13:48:27Z")

</div>

> [@teleivo](#):
>
> And is there any difference when you run this from your IDE?

when i run from the IDE is till get this error [stacktrace](https://pastebin.com/e0xg9nCj)

> [@teleivo](#):
>
> with `FileCopyUtils.copy(in, out);` with import `import org.springframework.util.FileCopyUtils;` The FileCopyUtils from Spring closes the in and outputstream.
> 
> I would be interested if that is solving it. Then we should have closed all stream/handles on the files JUnit wants to delete. At least that is my hope 😅

i have tried using `FileCopyUtils.copy(in, out)` from spring and on running the test in the IDE i get [java.io.IOException: Failed to delete temp directory C:\Users\Cliff\AppData\Loca - Pastebin.com](https://pastebin.com/JkQ9z5wF)

---

<div class="post-metadata">

**Author:** ![teleivo](https://talk.openmrs.org/user_avatar/talk.openmrs.org/teleivo/32/2015_2.png) [@teleivo](https://talk.openmrs.org/u/teleivo)\
**Post date:** [July 17, 2020, 1:49pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/29 "2020-07-17T13:49:55Z")

</div>

both tests are still failing?

---

<div class="post-metadata">

**Author:** ![gcliff](https://talk.openmrs.org/user_avatar/talk.openmrs.org/gcliff/32/8783_2.png) [@gcliff](https://talk.openmrs.org/u/gcliff)\
**Post date:** [July 17, 2020, 1:50pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/30 "2020-07-17T13:50:22Z")

</div>

> [@teleivo](#):
>
> Out of curiosity whats in the temp dir that cannot be deleted by JUnit?

its a appdir for unit tests

 ![tests](https://talk.openmrs.org/uploads/default/original/2X/5/5a8f9f93af588116cc1aea42592c2044c624d97e.png)

---

<div class="post-metadata">

**Author:** ![teleivo](https://talk.openmrs.org/user_avatar/talk.openmrs.org/teleivo/32/2015_2.png) [@teleivo](https://talk.openmrs.org/u/teleivo)\
**Post date:** [July 17, 2020, 1:50pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/31 "2020-07-17T13:50:30Z")

</div>

if anyone has a good idea how we can figure out what is holding a reference to these temporary files that are created during the tests. please let me know

---

<div class="post-metadata">

**Author:** ![gcliff](https://talk.openmrs.org/user_avatar/talk.openmrs.org/gcliff/32/8783_2.png) [@gcliff](https://talk.openmrs.org/u/gcliff)\
**Post date:** [July 17, 2020, 1:53pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/32 "2020-07-17T13:53:07Z")

</div>

> [@teleivo](#):
>
> both tests are still failing?

yes sir …

---

<div class="post-metadata">

**Author:** ![gcliff](https://talk.openmrs.org/user_avatar/talk.openmrs.org/gcliff/32/8783_2.png) [@gcliff](https://talk.openmrs.org/u/gcliff)\
**Post date:** [July 17, 2020, 1:57pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/33 "2020-07-17T13:57:12Z")

</div>

@teleivo how about i delete the folders inside the Temp folder and then try to build again …

May be if i may ask ,are these numerous `appdir-for-unit-tests files` in the Temp folder generated automatically during maven build ?

@ibacher @dkayiwa

---

<div class="post-metadata">

**Author:** ![teleivo](https://talk.openmrs.org/user_avatar/talk.openmrs.org/teleivo/32/2015_2.png) [@teleivo](https://talk.openmrs.org/u/teleivo)\
**Post date:** [July 17, 2020, 5:14pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/34 "2020-07-17T17:14:01Z")

</div>

@gcliff I meant what is inside the folders. I am assuming the mp3 files created during the test.

I will disable the tests on Windows using @achilep proposal for now. The tests will still run in all our pipelines which ensures the behavior of the code will not change. In the meantime I will try to replicate your environment and the errors you are seeing. So that I can investigate more easily and look for a fix 👌

---

<div class="post-metadata">

**Author:** ![teleivo](https://talk.openmrs.org/user_avatar/talk.openmrs.org/teleivo/32/2015_2.png) [@teleivo](https://talk.openmrs.org/u/teleivo)\
**Post date:** [July 17, 2020, 5:39pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/35 "2020-07-17T17:39:47Z")

</div>

@gcliff I pushed @achilep suggestion. So these 2 tests that fail on your machine should now be disabled on Windows.

---

<div class="post-metadata">

**Author:** ![teleivo](https://talk.openmrs.org/user_avatar/talk.openmrs.org/teleivo/32/2015_2.png) [@teleivo](https://talk.openmrs.org/u/teleivo)\
**Post date:** [July 17, 2020, 5:59pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/36 "2020-07-17T17:59:52Z")

</div>

This will be hard 😓So @gcliff my research tells me you run Windows 7, correct? I was able to run the tests inside a Microsoft provided docker image with JDK8 [https://hub.docker.com/\_/microsoft-java-jdk](https://hub.docker.com/_/microsoft-java-jdk) but I assume that was naive since that is most likely very different from actual Windows since its meant for deploying things to Azure.

for the curious this is what you do

```auto
docker pull mcr.microsoft.com/java/maven:8-zulu-debian9
docker run -it --name windows -v ~/.m2:/root/.m2 -v ~/code/openmrs/openmrs-core:/code --workdir /code mcr.microsoft.com/java/maven:8-zulu-debian9 sh
mvn clean test -Dtest=BinaryStreamHandlerTest,MediaHandlerTest

```

I will most likely need to setup a VM. Not sure yet if I can get a Windows 7.

---

<div class="post-metadata">

**Author:** ![ibacher](https://talk.openmrs.org/user_avatar/talk.openmrs.org/ibacher/32/19751_2.png) [@ibacher](https://talk.openmrs.org/u/ibacher)\
**Post date:** [July 17, 2020, 6:09pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/37 "2020-07-17T18:09:24Z")

</div>

> [@teleivo](#):
>
> ```auto
> docker pull mcr.microsoft.com/java/maven:8-zulu-debian9
> 
> ```

Just to point this out, you’ve actually pulled a Microsoft-provided Debian image, which really doesn’t help with the Windows-specific file handling issue. The minimal Windows image seems to be called 8-zulu-windowsservercore…

---

<div class="post-metadata">

**Author:** ![ibacher](https://talk.openmrs.org/user_avatar/talk.openmrs.org/ibacher/32/19751_2.png) [@ibacher](https://talk.openmrs.org/u/ibacher)\
**Post date:** [July 17, 2020, 6:23pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/38 "2020-07-17T18:23:59Z")

</div>

> [@gcliff](#):
>
> May be if i may ask ,are these numerous `appdir-for-unit-tests files` in the Temp folder generated automatically during maven build ?

They’re generated [here](https://github.com/openmrs/openmrs-core/blob/aff6a214fe2a2ed3fe6da29799fc12eef21e94a2/api/src/test/java/org/openmrs/test/BaseContextSensitiveTest.java#L356) in the `BaseContextSensitiveTest` class which means that we generate probably 200ish directories per Maven build. They should be deleted on exit, but apparently some aren’t. Although I don’t get the exception you’re reporting on my machine (I use a Mac), I do see a number of those `appdir-for-unit-tests-` directories piled up in my temporary files location. When I clean the temp directory and re-run the tests, I end up with 11 hanging `appdir-for-unit-tests-` directories.

---

<div class="post-metadata">

**Author:** ![ibacher](https://talk.openmrs.org/user_avatar/talk.openmrs.org/ibacher/32/19751_2.png) [@ibacher](https://talk.openmrs.org/u/ibacher)\
**Post date:** [July 17, 2020, 6:28pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/39 "2020-07-17T18:28:12Z")

</div>

[Here](https://pastebin.com/kvRM5B2n) is the full listing of files that aren’t getting cleaned up on exit (for my machine).’

@gcliff If you could get a similar listing for your machine, it might be helpful in tracking down where we have unclosed files.

---

<div class="post-metadata">

**Author:** ![teleivo](https://talk.openmrs.org/user_avatar/talk.openmrs.org/teleivo/32/2015_2.png) [@teleivo](https://talk.openmrs.org/u/teleivo)\
**Post date:** [July 17, 2020, 6:39pm UTC](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/40 "2020-07-17T18:39:27Z")

</div>

Thanks at @ibacher, if you remove the `@DisabledOnOs(WINDOWS)` flag on for example the `MediaHandlerTest` does it fail telling you the Jupiter Extension could not delete the temp dir because some other process was holding on to things in there (like in @gcliff logs)?

I just ran spotbugs on openmrs-core. Both tests that fail on Windows have a [Bug descriptions — spotbugs 4.7.1 documentation](https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html#obl-method-may-fail-to-clean-up-stream-or-resource-obl-unsatisfied-obligation) on the getObs() method. They are both creating an InputStream pass them on to the ComplexData.data and never close it. See here for example [openmrs-core/MediaHandler.java at master · openmrs/openmrs-core · GitHub](https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/obs/handler/MediaHandler.java#L62)

I just pushed [TRUNK-5816 Attempt fix failing HandlerTests on Windows · openmrs/openmrs-core@6dc1a74 · GitHub](https://github.com/openmrs/openmrs-core/commit/6dc1a7451c3fc60a9687e7ebb31f197d8b443932) in an attempt to close them myself in the test.

Can you @ibacher and @gcliff please run the MediaHandlerTest and BinaryStreamHandlerTest (remove the `@DisabledOn`) and let me know if that changes anything?

 ![Screen Shot 2020-07-17 at 20.25.34](https://talk.openmrs.org/uploads/default/original/2X/c/cc32275fe8e44b69cd3d96baf71700d4d7b05f7a.png) ![Screen Shot 2020-07-17 at 20.25.17](https://talk.openmrs.org/uploads/default/original/2X/1/1c02f37569b9a3ab27a4a1b4b8e8303cf5520c09.png)

[Previous page](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471.md?page=1)

[Next page](https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471.md?page=3)
