Created
November 26, 2025 18:38
-
-
Save wellington1993/e730c35105f41f97079a8a974cd48bcb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NUM_THREADS.times do |i| | |
| threads << Thread.new do | |
| while (endpoint = (endpoint_queue.pop(true) rescue nil)) | |
| puts "--- [Thread #{i+1}] Iniciando teste para: #{endpoint} ---" | |
| # 1) Lê token atual de forma segura | |
| current_access_token = token_mutex.synchronize { shared_tokens[:access] } | |
| stdout, stderr, status = Open3.capture3( | |
| "schemathesis", "run", temp_schema_file, "--url", API_BASE_URL, | |
| "--include-path-regex", endpoint, | |
| "-H", "Authorization: Bearer #{current_access_token}", | |
| "-H", "User-Agent: #{USER_AGENT}" | |
| ) | |
| endpoint_log_output = stdout + stderr | |
| # 2) Verifica se houve erro de autenticação | |
| if endpoint_log_output.match?(/Authentication failed|403 Forbidden|JWT signature|Access token inválido/) | |
| puts "--- [Thread #{i+1}] Token possivelmente inválido. Renovando... ---" | |
| new_access_token = nil | |
| new_refresh_token = nil | |
| # 3) Renova tokens de forma exclusiva | |
| token_mutex.synchronize do | |
| # Garante que ainda temos refresh válido | |
| current_refresh = shared_tokens[:refresh] | |
| unless current_refresh | |
| puts "ERRO FATAL: Refresh token ausente ao tentar renovar." | |
| exit 1 | |
| end | |
| new_access_token, new_refresh_token = renovar_access_token(current_refresh) | |
| shared_tokens[:access] = new_access_token | |
| shared_tokens[:refresh] = new_refresh_token | |
| end | |
| # 4) Retesta com o novo access_token (fora do mutex) | |
| puts "--- [Thread #{i+1}] Retestando Endpoint: #{endpoint} (com novo token) ---" | |
| stdout, stderr, status = Open3.capture3( | |
| "schemathesis", "run", temp_schema_file, "--url", API_BASE_URL, | |
| "--include-path-regex", endpoint, | |
| "-H", "Authorization: Bearer #{new_access_token}", | |
| "-H", "User-Agent: #{USER_AGENT}" | |
| ) | |
| endpoint_log_output += "\n\n--- RETESTE APÓS RENOVAÇÃO DO TOKEN ---\n\n" + stdout + stderr | |
| end | |
| specific_5xx_failures = parse_5xxx_fails(endpoint_log_output) | |
| if specific_5xx_failures.empty? | |
| puts "--- [Thread #{i+1}] Teste para #{endpoint} concluído. Nenhum erro 5xx encontrado. ---" | |
| else | |
| puts "--- [Thread #{i+1}] ERRO 5xx DETECTADO para #{endpoint}! ---" | |
| error_details_for_db = specific_5xx_failures.join("\n\n---\n\n") | |
| log_db(endpoint, endpoint_log_output, error_details_for_db) | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment