Nef10 / SwiftScraper

Web scraping library for Swift
MIT License
2 stars 0 forks source link

WaitForCondition Step: Fix race condition #15

Closed Nef10 closed 2 years ago

Nef10 commented 2 years ago

Sometimes the evaluation of the check script takes more then the 0.1 sec between the runs, which means a second run is triggered while the first one is still running. If the first on is now successful, and the second one returns before the reset function is fully executed, the completion handler might be called multiple times, advancing more steps then it should.

To fix this, we now only trigger the javascript check function 0.1 sec after the last one returned.

github-actions[bot] commented 2 years ago

Coverage after merging timer into main

91.67%

Coverage Report
FileStmtsFuncsLinesUncovered Lines
/Users/runner/work/SwiftScraper/SwiftScraper/Sources/SwiftScraper
   Browser.swift75%65.38%76.51%130–138, 142, 163–164, 173–184, 197–198, 210–211, 235–236, 72, 79
   JavaScriptGenerator.swift100%100%100%
   StepRunner.swift95.80%90.91%96.30%136, 175–177
   SwiftScraperError.swift100%100%100%
/Users/runner/work/SwiftScraper/SwiftScraper/Sources/SwiftScraper/Steps
   AsyncProcessStep.swift100%100%100%
   AsyncScriptStep.swift100%100%100%
   OpenPageStep.swift96.55%100%96.15%28
   PageChangeStep.swift92.68%80%94.44%48
   ProcessStep.swift100%100%100%
   ScriptStep.swift98.04%100%97.78%61
   WaitForConditionStep.swift95.60%85.71%96.43%51, 65
   WaitStep.swift100%100%100%
/Users/runner/work/SwiftScraper/SwiftScraper/Sources/SwiftScraper/Steps/Common
   NavigableStep.swift100%100%100%
   StepCompletionCallback.swift100%100%100%
   StepFlowResult.swift100%100%100%