Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(download): use CURRENT_ENGINES_HASH and debug urlExists() #17686

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/fetch-engine/src/__tests__/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ It took ${timeInMsToDownloadAllFromCache2}ms to execute download() for all binar
binaries: {
'query-engine': baseDir,
},
version: FIXED_ENGINES_HASH,
version: CURRENT_ENGINES_HASH,
})

fs.writeFileSync(targetPath, 'incorrect-binary')
Expand All @@ -454,7 +454,7 @@ It took ${timeInMsToDownloadAllFromCache2}ms to execute download() for all binar
binaries: {
'query-engine': baseDir,
},
version: FIXED_ENGINES_HASH,
version: CURRENT_ENGINES_HASH,
})

expect(fs.existsSync(targetPath)).toBe(true)
Expand All @@ -468,8 +468,8 @@ It took ${timeInMsToDownloadAllFromCache2}ms to execute download() for all binar
binaries: {
'query-engine': __dirname,
},
version: FIXED_ENGINES_HASH,
binaryTargets: ['darwin', 'marvin'] as any, // eslint-disable-line @typescript-eslint/no-explicit-any
version: CURRENT_ENGINES_HASH,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unknown binaryTarget marvin and no custom engine files were provided"`,
Expand All @@ -484,8 +484,8 @@ It took ${timeInMsToDownloadAllFromCache2}ms to execute download() for all binar
binaries: {
'query-engine': __dirname,
},
version: FIXED_ENGINES_HASH,
binaryTargets: ['darwin', 'marvin'] as any, // eslint-disable-line @typescript-eslint/no-explicit-any
version: CURRENT_ENGINES_HASH,
})
} catch (err: any) {
expect(stripAnsi(err.message)).toMatchInlineSnapshot(
Expand All @@ -499,6 +499,7 @@ It took ${timeInMsToDownloadAllFromCache2}ms to execute download() for all binar
binaries: {
'query-engine': __dirname,
},
version: CURRENT_ENGINES_HASH,
})
const dummyPath = e['query-engine']![Object.keys(e['query-engine']!)[0]]!
const targetPath = path.join(
Expand All @@ -514,6 +515,7 @@ It took ${timeInMsToDownloadAllFromCache2}ms to execute download() for all binar
'query-engine': path.join(__dirname, 'all'),
},
binaryTargets: ['marvin'] as any, // eslint-disable-line @typescript-eslint/no-explicit-any
version: CURRENT_ENGINES_HASH,
})
expect(testResult['query-engine']!['marvin']).toEqual(targetPath)
})
Expand Down
24 changes: 17 additions & 7 deletions packages/fetch-engine/src/getLatestTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ async function getFirstFinishedCommit(branch: string, commits: string[]): Promis
console.log(
`${chalk.blueBright(
'info',
)} The engine commit ${commit} is not yet done. We're skipping it as we're in dev. Missing urls: ${
)} The engine commit ${commit} is not yet built?. We're skipping it. Missing urls (${
missing.length
}`,
}):\n${missing.join('\n')}`,
)
}
}
Expand All @@ -97,20 +97,30 @@ async function getFirstFinishedCommit(branch: string, commits: string[]): Promis
export async function urlExists(url) {
try {
const res = await fetch(url, {
// So we don't download the whole file
method: 'HEAD',
agent: getProxyAgent(url) as any,
})

const headers = fromEntries(res.headers.entries())
if (res.status > 200) {
// console.error(res, headers)
console.error(`url: ${url} failed - http code > 200: ${res.status}`)
console.error(res, headers)
}
if (parseInt(headers['content-length']) > 0) {
return res.status < 300
const bodyLength = parseInt(headers['content-length'] || '0', 10)
if (bodyLength > 0) {
// If status is < 300 and body is not empty, it exists
// Success!
if (res.status < 300) {
return true
} else {
console.error(`url: ${url} failed - http code >= 300: ${res.status}`)
console.error(res, headers)
return false
}
}
} catch (e) {
//
// console.error(e)
console.error(`urlExists("${url}") failed:`, e)
}
return false
}
Expand Down