Procházet zdrojové kódy

Add pagination for HTTP replay files and remove exception stopping

Sam King před 5 měsíci
rodič
revize
4f22000edb

+ 0 - 1
TrioTests/OpenAPSSwiftTests/AutosensJsonTests.swift

@@ -128,7 +128,6 @@ import Testing
                 }
                 if let str = algorithmComparison.swiftException {
                     print(str)
-                    #expect(Bool(false), "Swift exception on autosens")
                 }
                 continue
             }

+ 0 - 1
TrioTests/OpenAPSSwiftTests/DetermineBasalJsonTests.swift

@@ -27,7 +27,6 @@ import Testing
                 }
                 if let str = algorithmComparison.swiftException {
                     print(str)
-                    #expect(Bool(false), "Swift exception on determine")
                 }
                 continue
             }

+ 0 - 1
TrioTests/OpenAPSSwiftTests/IobJsonTests.swift

@@ -58,7 +58,6 @@ import Testing
                 }
                 if let str = algorithmComparison.swiftException {
                     print(str)
-                    #expect(Bool(false), "Swift exception on IoB")
                 }
                 continue
             }

+ 0 - 1
TrioTests/OpenAPSSwiftTests/MealJsonTests.swift

@@ -27,7 +27,6 @@ import Testing
                 }
                 if let str = algorithmComparison.swiftException {
                     print(str)
-                    #expect(Bool(false), "Swift exception on meal")
                 }
                 continue
             }

+ 17 - 2
TrioTests/OpenAPSSwiftTests/utils/HttpFiles.swift

@@ -2,14 +2,29 @@ import Foundation
 @testable import Trio
 
 /// Helper struct to download files from localhost via HTTP. Must have a HTTP server
-/// running on port 8123 that supports listing files and downloading files
+/// running on port 8123 that supports listing files and downloading files.
+///
+/// You can set two environment variables `HTTP_FILES_OFFSET` and `HTTP_FILES_LENGTH`
+/// to implement paging
 ///
 /// This struct is only useful during testing as it is missing a number of error checks
 struct HttpFiles {
     static func listFiles() async throws -> [String] {
         let url = URL(string: "http://localhost:8123/list")!
         let (data, _) = try await URLSession.shared.data(from: url)
-        let files = try JSONDecoder().decode([String].self, from: data)
+        let allFiles = try JSONDecoder().decode([String].self, from: data)
+        
+        let files: [String]
+        let env = ProcessInfo.processInfo.environment
+        if let offsetString = env["HTTP_FILES_OFFSET"], let lengthString = env["HTTP_FILES_LENGTH"], let offset = Int(offsetString), let length = Int(lengthString) {
+            // Both variables exist and are valid integers
+            let endIndex = min(offset + length, allFiles.count)
+            let startIndex = min(offset, allFiles.count)
+            files = Array(allFiles[startIndex..<endIndex])
+        } else {
+            files = allFiles
+        }
+        
         return files
     }