|
| 1 | +#lang racket/base |
| 2 | + |
| 3 | +(require racket/contract/base |
| 4 | + racket/string |
| 5 | + rackunit |
| 6 | + resyntax/default-recommendations/analyzers/identifier-usage |
| 7 | + resyntax/default-recommendations/analyzers/variable-mutability |
| 8 | + resyntax/default-recommendations/analyzers/ignored-result-values |
| 9 | + resyntax/default-recommendations/analyzers/function-expression-analyzer |
| 10 | + resyntax/private/analysis |
| 11 | + resyntax/private/source) |
| 12 | + |
| 13 | +;; Load tests for expansion analyzers to ensure they can handle large files |
| 14 | +;; within reasonable timeouts. These tests are designed to catch severe |
| 15 | +;; performance regressions where analyzers would take minutes or hang on |
| 16 | +;; moderately large files. |
| 17 | + |
| 18 | +(define timeout-ms 30000) ; 30 second timeout for load tests |
| 19 | + |
| 20 | +;; Generate a large test file with many definitions and function calls. |
| 21 | +;; This creates a file with approximately 300+ lines of code with various |
| 22 | +;; constructs that analyzers need to process. The file is large enough to |
| 23 | +;; exercise analyzer performance but small enough to complete in reasonable time. |
| 24 | +(define (generate-large-test-program) |
| 25 | + (string-join |
| 26 | + (append |
| 27 | + (list "#lang racket/base" |
| 28 | + "" |
| 29 | + "(require racket/list racket/string)" |
| 30 | + "") |
| 31 | + ;; Generate many function definitions |
| 32 | + (for/list ([i (in-range 25)]) |
| 33 | + (format "(define (func~a x y) |
| 34 | + (let ([a (+ x y)] |
| 35 | + [b (* x y)]) |
| 36 | + (if (> a b) |
| 37 | + (+ a b) |
| 38 | + (* a b))))" i)) |
| 39 | + (list "") |
| 40 | + ;; Generate many variable definitions |
| 41 | + (for/list ([i (in-range 30)]) |
| 42 | + (format "(define var~a ~a)" i i)) |
| 43 | + (list "") |
| 44 | + ;; Generate many mutable variables with assignments |
| 45 | + (for/list ([i (in-range 20)]) |
| 46 | + (format "(define mut~a 0) |
| 47 | +(set! mut~a ~a)" i i i)) |
| 48 | + (list "") |
| 49 | + ;; Generate function calls with various patterns |
| 50 | + (for/list ([i (in-range 25)]) |
| 51 | + (format "(void (func~a var~a (+ var~a ~a)))" |
| 52 | + (modulo i 25) |
| 53 | + (modulo i 30) |
| 54 | + (modulo (+ i 1) 30) |
| 55 | + i)) |
| 56 | + (list "") |
| 57 | + ;; Generate nested expressions with ignored results |
| 58 | + (for/list ([i (in-range 15)]) |
| 59 | + (format "(begin |
| 60 | + (+ ~a ~a) |
| 61 | + (void ~a))" i (+ i 1) i))) |
| 62 | + "\n")) |
| 63 | + |
| 64 | +(define large-test-source (string-source (generate-large-test-program))) |
| 65 | + |
| 66 | +(test-case "identifier-usage-analyzer load test" |
| 67 | + ;; This test ensures the identifier-usage-analyzer can analyze a large file |
| 68 | + ;; within the timeout period. |
| 69 | + (define start-time (current-inexact-milliseconds)) |
| 70 | + (define analysis |
| 71 | + (source-analyze large-test-source |
| 72 | + #:analyzers (list identifier-usage-analyzer) |
| 73 | + #:timeout-ms timeout-ms)) |
| 74 | + (define elapsed-ms (- (current-inexact-milliseconds) start-time)) |
| 75 | + |
| 76 | + ;; Verify the analysis completed successfully |
| 77 | + (check-true (source-code-analysis? analysis)) |
| 78 | + |
| 79 | + ;; Verify it completed within the timeout (with some margin) |
| 80 | + (check-true (< elapsed-ms timeout-ms) |
| 81 | + (format "identifier-usage-analyzer took ~a ms, expected < ~a ms" |
| 82 | + elapsed-ms |
| 83 | + timeout-ms))) |
| 84 | + |
| 85 | +(test-case "variable-mutability-analyzer load test" |
| 86 | + ;; This test ensures the variable-mutability-analyzer can analyze a large file |
| 87 | + ;; within the timeout period. |
| 88 | + (define start-time (current-inexact-milliseconds)) |
| 89 | + (define analysis |
| 90 | + (source-analyze large-test-source |
| 91 | + #:analyzers (list variable-mutability-analyzer) |
| 92 | + #:timeout-ms timeout-ms)) |
| 93 | + (define elapsed-ms (- (current-inexact-milliseconds) start-time)) |
| 94 | + |
| 95 | + ;; Verify the analysis completed successfully |
| 96 | + (check-true (source-code-analysis? analysis)) |
| 97 | + |
| 98 | + ;; Verify it completed within the timeout (with some margin) |
| 99 | + (check-true (< elapsed-ms timeout-ms) |
| 100 | + (format "variable-mutability-analyzer took ~a ms, expected < ~a ms" |
| 101 | + elapsed-ms |
| 102 | + timeout-ms))) |
| 103 | + |
| 104 | +(test-case "ignored-result-values-analyzer load test" |
| 105 | + ;; This test ensures the ignored-result-values-analyzer can analyze a large file |
| 106 | + ;; within the timeout period. |
| 107 | + (define start-time (current-inexact-milliseconds)) |
| 108 | + (define analysis |
| 109 | + (source-analyze large-test-source |
| 110 | + #:analyzers (list ignored-result-values-analyzer) |
| 111 | + #:timeout-ms timeout-ms)) |
| 112 | + (define elapsed-ms (- (current-inexact-milliseconds) start-time)) |
| 113 | + |
| 114 | + ;; Verify the analysis completed successfully |
| 115 | + (check-true (source-code-analysis? analysis)) |
| 116 | + |
| 117 | + ;; Verify it completed within the timeout (with some margin) |
| 118 | + (check-true (< elapsed-ms timeout-ms) |
| 119 | + (format "ignored-result-values-analyzer took ~a ms, expected < ~a ms" |
| 120 | + elapsed-ms |
| 121 | + timeout-ms))) |
| 122 | + |
| 123 | +(test-case "function-expression-analyzer load test" |
| 124 | + ;; This test ensures the function-expression-analyzer can analyze a large file |
| 125 | + ;; within the timeout period. |
| 126 | + (define start-time (current-inexact-milliseconds)) |
| 127 | + (define analysis |
| 128 | + (source-analyze large-test-source |
| 129 | + #:analyzers (list function-expression-analyzer) |
| 130 | + #:timeout-ms timeout-ms)) |
| 131 | + (define elapsed-ms (- (current-inexact-milliseconds) start-time)) |
| 132 | + |
| 133 | + ;; Verify the analysis completed successfully |
| 134 | + (check-true (source-code-analysis? analysis)) |
| 135 | + |
| 136 | + ;; Verify it completed within the timeout (with some margin) |
| 137 | + (check-true (< elapsed-ms timeout-ms) |
| 138 | + (format "function-expression-analyzer took ~a ms, expected < ~a ms" |
| 139 | + elapsed-ms |
| 140 | + timeout-ms))) |
| 141 | + |
| 142 | +(test-case "all analyzers together load test" |
| 143 | + ;; This test ensures all analyzers can work together on a large file |
| 144 | + ;; within the timeout period. |
| 145 | + (define all-analyzers |
| 146 | + (list identifier-usage-analyzer |
| 147 | + variable-mutability-analyzer |
| 148 | + ignored-result-values-analyzer |
| 149 | + function-expression-analyzer)) |
| 150 | + |
| 151 | + (define start-time (current-inexact-milliseconds)) |
| 152 | + (define analysis |
| 153 | + (source-analyze large-test-source |
| 154 | + #:analyzers all-analyzers |
| 155 | + #:timeout-ms timeout-ms)) |
| 156 | + (define elapsed-ms (- (current-inexact-milliseconds) start-time)) |
| 157 | + |
| 158 | + ;; Verify the analysis completed successfully |
| 159 | + (check-true (source-code-analysis? analysis)) |
| 160 | + |
| 161 | + ;; Verify it completed within the timeout (with some margin) |
| 162 | + (check-true (< elapsed-ms timeout-ms) |
| 163 | + (format "all analyzers together took ~a ms, expected < ~a ms" |
| 164 | + elapsed-ms |
| 165 | + timeout-ms))) |
0 commit comments