]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mongodb] Fix `MongoDBPersistenceServiceTest` fails on CPU without AVX support (...
authorulbi <rene_ulbricht@outlook.com>
Sun, 14 Jul 2024 08:01:35 +0000 (10:01 +0200)
committerGitHub <noreply@github.com>
Sun, 14 Jul 2024 08:01:35 +0000 (10:01 +0200)
Fixes #17046

Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
bundles/org.openhab.persistence.mongodb/src/test/java/org/openhab/persistence/mongodb/internal/DataCreationHelper.java
bundles/org.openhab.persistence.mongodb/src/test/java/org/openhab/persistence/mongodb/internal/MongoDBPersistenceServiceTest.java

index 83ecd75b40c0721f0553ac5779acbdf750d9e70a..ac4deaf77322cb4bf14b8b103e35b08e1bf7226a 100644 (file)
@@ -15,6 +15,9 @@ package org.openhab.persistence.mongodb.internal;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
 import java.time.LocalDate;
 import java.time.ZonedDateTime;
 import java.util.ArrayList;
@@ -224,6 +227,26 @@ public class DataCreationHelper {
                         new QuantityType<>("25.00 °F"))));
     }
 
+    /**
+     * Checks if the current system supports AVX (Advanced Vector Extensions).
+     * AVX is a set of CPU instructions that can greatly improve performance for certain operations.
+     *
+     * @return true if AVX is supported, false otherwise
+     */
+    public static boolean isAVXSupported() {
+        try (BufferedReader reader = new BufferedReader(new FileReader("/proc/cpuinfo"))) {
+            String line;
+            while ((line = reader.readLine()) != null) {
+                if (line.toLowerCase().contains("avx")) {
+                    return true;
+                }
+            }
+        } catch (IOException e) {
+            return false;
+        }
+        return false;
+    }
+
     /**
      * Provides a stream of arguments to be used for parameterized tests.
      *
@@ -234,7 +257,7 @@ public class DataCreationHelper {
      * @return A stream of Arguments, each containing a DatabaseTestContainer instance.
      */
     public static Stream<Arguments> provideDatabaseBackends() {
-        if (DockerClientFactory.instance().isDockerAvailable()) {
+        if (DockerClientFactory.instance().isDockerAvailable() && isAVXSupported()) {
             // If Docker is available, create a stream of Arguments with all backends
             return Stream.of(
                     // Create a DatabaseTestContainer with a MemoryBackend
index dff84eacd1e737c249a39a49713bd4f71671fdc9..afd122c42aaf484242a0d97d4b094b3b5f9ed52b 100644 (file)
@@ -29,7 +29,6 @@ import java.util.stream.Collectors;
 
 import org.bson.Document;
 import org.bson.types.ObjectId;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.MethodSource;
@@ -63,7 +62,6 @@ import de.bwaldvogel.mongo.backend.memory.MemoryBackend;
  *
  * @author René Ulbricht - Initial contribution
  */
-@Disabled("Fails on CPUs without AVX support, see: https://github.com/openhab/openhab-addons/issues/17046")
 public class MongoDBPersistenceServiceTest {
 
     /**