From be22370ec0dade6e7bfdf55dc3c4d014f6e87130 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Thu, 30 Oct 2025 23:15:18 +0000 Subject: [PATCH] finally wrote a funcitonal good test!!!! added undownloadedemojisbefore unused atm using a withThrowingDiscardingTaskGroup with a task limit task limit: max tasks is cores-1 every tiem a task is added taskcount+=1 every tiem it finishes taskcount -= 1 if active tasks> maxtasks wait until i > what it was before reduce activetasks by one deleting images in pass 2 guard that it was downloaded before basic async cos i cba atp doThing wiht inout i to increment itll download the image and make sure its not already downloaded etc --- StickerSlack.xcodeproj/project.pbxproj | 4 +- StickerSlackTests/StickerSlackTests.swift | 61 ++++++++++++++--------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index 3fdae57..9c2c14e 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -740,7 +740,7 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 8JGND254B7; GENERATE_INFOPLIST_FILE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 26.0; + IPHONEOS_DEPLOYMENT_TARGET = 17; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.neon443.StickerSlackTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -763,7 +763,7 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 8JGND254B7; GENERATE_INFOPLIST_FILE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 26.0; + IPHONEOS_DEPLOYMENT_TARGET = 17; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.neon443.StickerSlackTests; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/StickerSlackTests/StickerSlackTests.swift b/StickerSlackTests/StickerSlackTests.swift index a32155d..27d667e 100644 --- a/StickerSlackTests/StickerSlackTests.swift +++ b/StickerSlackTests/StickerSlackTests.swift @@ -50,38 +50,53 @@ struct PerformanceTests { } @Test func MSStickerValidation() async throws { + let undownloadedEmojisBefore = hoarder.emojis.filter { !$0.isLocal }.map { $0.id } let downloadedEmojisBefore = hoarder.emojis.filter { $0.isLocal }.map { $0.id } + try? await withThrowingDiscardingTaskGroup { group in + var i = 0 + let maxTasks = ProcessInfo.processInfo.processorCount-1 + var activeTasks = 0 + + for emoji in hoarder.emojis { + if activeTasks >= maxTasks { + let ib4 = i + while i <= ib4 { + try? await Task.sleep(nanoseconds: 1) + } + activeTasks -= 1 + } + group.addTask { + try? await doThing(on: emoji, i: &i) + activeTasks -= 1 + } + activeTasks += 1 + } + } + await withDiscardingTaskGroup { group in var i = 0 for emoji in hoarder.emojis { + emoji.deleteImage() + guard downloadedEmojisBefore.contains(emoji.id) else { continue } + async let (data, _) = try! URLSession.shared.data(from: emoji.remoteImageURL) + try! await data.write(to: emoji.localImageURL) i+=1 - group.addTask { - try? await Task.sleep(nanoseconds: 1) - async let (data, _) = try! URLSession.shared.data(from: emoji.remoteImageURL) - try! await data.write(to: emoji.localImageURL) - let _ = emoji.sticker?.validate() - print("\(i)/\(hoarder.emojis.count) \(emoji.name)") - } + print("\(i)/\(downloadedEmojisBefore.count) \(emoji.name)") } } - -// var i = 0 -// for emoji in hoarder.emojis { -// i+=1 -// async let (data, _) = try! URLSession.shared.data(from: emoji.remoteImageURL) -// try! await data.write(to: emoji.localImageURL) -// let _ = emoji.sticker?.validate() -// print("\(i)/\(hoarder.emojis.count) \(emoji.name)") -// } - - var i = 0 - for emoji in hoarder.emojis { - emoji.deleteImage() - guard downloadedEmojisBefore.contains(emoji.id) else { continue } - async let (data, _) = try! URLSession.shared.data(from: emoji.remoteImageURL) + } + + func doThing(on emoji: Emoji, i: inout Int) async throws { + do { + guard !emoji.isLocal else { return } + async let (data, _) = try URLSession.shared.data(from: emoji.remoteImageURL) try! await data.write(to: emoji.localImageURL) - print("\(i)/\(downloadedEmojisBefore) \(emoji.name)") + let _ = emoji.sticker?.validate() + i+=1 + print("\(i)/\(hoarder.emojis.count) \(emoji.name)") + } catch { + try! await doThing(on: emoji, i: &i) } } }