1
0
Fork 0

committing v1

pull/1613/head
Vallie Joseph 2023-12-22 03:51:47 +00:00
parent 98e1a813db
commit 7f47ffaee2
2 changed files with 73 additions and 15 deletions

View File

@ -120,27 +120,42 @@ const mockGetArtifactFailure = jest.fn(() => {
} }
}) })
const mockDelayBlobResponse = jest.fn(async () => { const mockDelayWritableResponse = jest.fn(async () => {
// await new Promise(r => setTimeout(r, 31000)) //const message = new stream.PassThrough()
const timeout = 31000
const message = new http.IncomingMessage(new net.Socket()) const message = new http.IncomingMessage(new net.Socket())
message.statusCode = 200
message.push('Internal Server Error')
message.push(null)
setTimeout(() => { setTimeout(() => {
message.emit('data', 'test response') message.emit('error', () => {})
}, 31000)
return {
message
}
})
const mockDelayBlobResponse = jest.fn(async () => {
const message = new http.IncomingMessage(new net.Socket())
message.on('data', () => {
setTimeout(() => { setTimeout(() => {
message.statusCode = 200 message.statusCode = 200
message.push('OK') message.push('OK')
message.push(null) message.push(null)
}, timeout) }, 31000)
}, timeout) })
// message // setTimeout(() => {
// .on('data', async () => { // setTimeout(() => {
// await new Promise(r => setTimeout(r, 31000))
// })
// .on('done', () => {
// message.statusCode = 200 // message.statusCode = 200
// message.push('OK') // message.push('OK')
// message.push(null) // message.push(null)
// }) // }, 31000)
// message.emit('data')
// }, 31000)
// message.on('done', () => {
// message.statusCode = 200
// message.push('OK')
// message.push(null)
// })
return { return {
message message
} }
@ -290,12 +305,18 @@ describe('download-artifact', () => {
const mockHttpClient = (HttpClient as jest.Mock).mockImplementation( const mockHttpClient = (HttpClient as jest.Mock).mockImplementation(
() => { () => {
return { return {
get: mockDelayBlobResponse get: mockDelayWritableResponse
} }
} }
) )
await downloadArtifactPublic(
fixtures.artifactID,
fixtures.repositoryOwner,
fixtures.repositoryName,
fixtures.token
)
await expect( expect(
downloadArtifactPublic( downloadArtifactPublic(
fixtures.artifactID, fixtures.artifactID,
fixtures.repositoryOwner, fixtures.repositoryOwner,
@ -303,7 +324,6 @@ describe('download-artifact', () => {
fixtures.token fixtures.token
) )
).rejects.toBeInstanceOf(Error) ).rejects.toBeInstanceOf(Error)
// jest.runAllTimers()
expect(downloadArtifactMock).toHaveBeenCalledWith({ expect(downloadArtifactMock).toHaveBeenCalledWith({
owner: fixtures.repositoryOwner, owner: fixtures.repositoryOwner,
@ -314,6 +334,40 @@ describe('download-artifact', () => {
redirect: 'manual' redirect: 'manual'
} }
}) })
expect(mockHttpClient).toHaveBeenCalledWith(getUserAgentString())
expect(mockGetArtifactFailure).toHaveBeenCalledWith(
fixtures.blobStorageUrl
)
expect(mockGetArtifactFailure).toHaveBeenCalledTimes(5)
// const mockHttpClient = (HttpClient as jest.Mock).mockImplementation(
// () => {
// return {
// get: mockDelayBlobResponse
// }
// }
// )
// expect(downloadArtifactMock).toHaveBeenCalledWith({
// owner: fixtures.repositoryOwner,
// repo: fixtures.repositoryName,
// artifact_id: fixtures.artifactID,
// archive_format: 'zip',
// request: {
// redirect: 'manual'
// }
// })
// expect(mockHttpClient).toHaveBeenCalledWith(getUserAgentString())
// expect(mockGetArtifactFailure).toHaveBeenCalledWith(
// fixtures.blobStorageUrl
// )
// await expect(
// downloadArtifactPublic(
// fixtures.artifactID,
// fixtures.repositoryOwner,
// fixtures.repositoryName,
// fixtures.token
// )
// ).rejects.toBeInstanceOf(Error)
}, 40000) }, 40000)
it('should fail if blob storage response is non-200 after 5 retries', async () => { it('should fail if blob storage response is non-200 after 5 retries', async () => {
const downloadArtifactMock = github.getOctokit(fixtures.token).rest const downloadArtifactMock = github.getOctokit(fixtures.token).rest

View File

@ -38,6 +38,7 @@ async function exists(path: string): Promise<boolean> {
} }
async function streamExtract(url: string, directory: string): Promise<void> { async function streamExtract(url: string, directory: string): Promise<void> {
core.info(`Stream extract started`)
let retryCount = 0 let retryCount = 0
while (retryCount < 5) { while (retryCount < 5) {
try { try {
@ -61,8 +62,11 @@ async function streamExtractInternal(
url: string, url: string,
directory: string directory: string
): Promise<void> { ): Promise<void> {
core.info(`Stream extract internal started`)
const client = new httpClient.HttpClient(getUserAgentString()) const client = new httpClient.HttpClient(getUserAgentString())
const response = await client.get(url) const response = await client.get(url)
core.info(`Stream extract internal get called`)
if (response.message.statusCode !== 200) { if (response.message.statusCode !== 200) {
throw new Error( throw new Error(