Attempt to limit failures in wrapper-validation tests (#490)

- Reduce requests involved in checksums.retryTest
- Reduce requests involved in validate test
- Fetch checksum values in batches
This commit is contained in:
Daz DeBoer 2024-12-17 17:58:41 -07:00 committed by GitHub
parent bc78598590
commit 59d7e81070
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 11 deletions

View File

@ -1,5 +1,6 @@
import * as httpm from 'typed-rest-client/HttpClient' import * as httpm from 'typed-rest-client/HttpClient'
import * as cheerio from 'cheerio' import * as cheerio from 'cheerio'
import * as core from '@actions/core'
import fileWrapperChecksums from './wrapper-checksums.json' import fileWrapperChecksums from './wrapper-checksums.json'
@ -59,12 +60,7 @@ export async function fetchUnknownChecksums(
} }
const wrapperChecksums = new WrapperChecksums() const wrapperChecksums = new WrapperChecksums()
await Promise.all( await fetchAndStoreChecksums(checksumUrls, wrapperChecksums)
checksumUrls.map(async ([version, url]) => {
const checksum = await httpGetText(url)
wrapperChecksums.add(version, checksum)
})
)
return wrapperChecksums return wrapperChecksums
} }
@ -94,3 +90,20 @@ async function addDistributionSnapshotChecksumUrls(checksumUrls: [string, string
} }
}) })
} }
async function fetchAndStoreChecksums(
checksumUrls: [string, string][],
wrapperChecksums: WrapperChecksums
): Promise<void> {
const batchSize = 10
for (let i = 0; i < checksumUrls.length; i += batchSize) {
const batch = checksumUrls.slice(i, i + batchSize)
await Promise.all(
batch.map(async ([version, url]) => {
const checksum = await httpGetText(url)
wrapperChecksums.add(version, checksum)
})
)
core.info(`Fetched ${i + batch.length} of ${checksumUrls.length} checksums`)
}
}

View File

@ -2,7 +2,7 @@ import * as checksums from '../../../src/wrapper-validation/checksums'
import nock from 'nock' import nock from 'nock'
import {afterEach, describe, expect, test, jest} from '@jest/globals' import {afterEach, describe, expect, test, jest} from '@jest/globals'
jest.setTimeout(30000) jest.setTimeout(60000)
const CHECKSUM_8_1 = 'ed2c26eba7cfb93cc2b7785d05e534f07b5b48b5e7fc941921cd098628abca58' const CHECKSUM_8_1 = 'ed2c26eba7cfb93cc2b7785d05e534f07b5b48b5e7fc941921cd098628abca58'
@ -70,8 +70,8 @@ describe('retry', () => {
code: 'ECONNREFUSED' code: 'ECONNREFUSED'
}) })
const validChecksums = await checksums.fetchUnknownChecksums(false, new checksums.WrapperChecksums) const validChecksums = await checksums.fetchUnknownChecksums(false, knownChecksumsWithout8_1())
expect(validChecksums.checksums.size).toBeGreaterThan(10) expect(validChecksums.checksums.size).toBeGreaterThan(0)
nock.isDone() nock.isDone()
}) })
}) })

View File

@ -2,7 +2,7 @@ import * as path from 'path'
import * as fs from 'fs' import * as fs from 'fs'
import * as validate from '../../../src/wrapper-validation/validate' import * as validate from '../../../src/wrapper-validation/validate'
import {expect, test, jest} from '@jest/globals' import {expect, test, jest} from '@jest/globals'
import { WrapperChecksums } from '../../../src/wrapper-validation/checksums' import { WrapperChecksums, KNOWN_CHECKSUMS } from '../../../src/wrapper-validation/checksums'
import { ChecksumCache } from '../../../src/wrapper-validation/cache' import { ChecksumCache } from '../../../src/wrapper-validation/cache'
import exp from 'constants' import exp from 'constants'
@ -11,6 +11,21 @@ jest.setTimeout(30000)
const baseDir = path.resolve('./test/jest/wrapper-validation') const baseDir = path.resolve('./test/jest/wrapper-validation')
const tmpDir = path.resolve('./test/jest/tmp') const tmpDir = path.resolve('./test/jest/tmp')
const CHECKSUM_3888 = '3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce'
function knownChecksumsWithout3888(): WrapperChecksums {
const knownChecksums = new WrapperChecksums()
// iterate over all known checksums and add them to the knownChecksums object
for (const [checksum, versions] of KNOWN_CHECKSUMS.checksums) {
if (checksum !== CHECKSUM_3888) {
for (const version of versions) {
knownChecksums.add(version, checksum)
}
}
}
return knownChecksums
}
test('succeeds if all found wrapper jars are valid', async () => { test('succeeds if all found wrapper jars are valid', async () => {
const result = await validate.findInvalidWrapperJars(baseDir, false, [ const result = await validate.findInvalidWrapperJars(baseDir, false, [
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
@ -47,7 +62,7 @@ test('succeeds if all found wrapper jars are previously valid', async () => {
}) })
test('succeeds if all found wrapper jars are valid (and checksums are fetched from Gradle API)', async () => { test('succeeds if all found wrapper jars are valid (and checksums are fetched from Gradle API)', async () => {
const knownValidChecksums = new WrapperChecksums() const knownValidChecksums = knownChecksumsWithout3888()
const result = await validate.findInvalidWrapperJars( const result = await validate.findInvalidWrapperJars(
baseDir, baseDir,
false, false,