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

添加支持多 host 自动切换 & 补全测试 #505

Merged
merged 28 commits into from
May 14, 2021

Conversation

yinxulai
Copy link
Collaborator

@yinxulai yinxulai commented Apr 28, 2021

本次改动

  • 支持多个 host,当某个不可用时可自动切换
  • 疯狂 提升测试覆盖率

image

* @returns Promise
* @description 直传接口
*/
export function direct(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

挪进来是为了方便统一 mock 测试

@codecov
Copy link

codecov bot commented Apr 28, 2021

Codecov Report

Merging #505 (2898a03) into master (671e54e) will increase coverage by 29.13%.
The diff coverage is 85.38%.

❗ Current head 2898a03 differs from pull request most recent head 19c85f6. Consider uploading reports for the commit 19c85f6 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           master     #505       +/-   ##
===========================================
+ Coverage   43.22%   72.36%   +29.13%     
===========================================
  Files          15       20        +5     
  Lines         849     1071      +222     
  Branches      155      206       +51     
===========================================
+ Hits          367      775      +408     
+ Misses        472      296      -176     
+ Partials       10        0       -10     
Impacted Files Coverage Δ
src/utils/compress.ts 16.98% <16.66%> (+0.63%) ⬆️
src/utils/helper.ts 53.84% <54.76%> (+18.84%) ⬆️
src/api/index.ts 51.21% <75.00%> (-10.55%) ⬇️
src/upload/base.ts 82.56% <84.61%> (+66.71%) ⬆️
src/upload/resume.ts 93.68% <88.23%> (+79.39%) ⬆️
src/upload/index.ts 93.10% <90.00%> (+61.10%) ⬆️
src/logger/index.ts 96.42% <90.90%> (+0.59%) ⬆️
src/api/index.mock.ts 94.87% <94.87%> (ø)
src/utils/config.ts 95.00% <95.00%> (ø)
src/config/index.ts 100.00% <100.00%> (ø)
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 671e54e...19c85f6. Read the comment docs.

return this.callInterceptor('initUploadParts', defaultData, ...args)
}

public deleteUploadedChunks(...args: any[]): ReturnType<typeof api.deleteUploadedChunks> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

方法没地方用,所以测不到

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要的话,单独写个这个方法的 test 就好了?

new Logger('', true, 'OFF')
const last = new Logger('', true, 'OFF')
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
Copy link
Collaborator Author

@yinxulai yinxulai Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为了使用 private 的属性用了 // @ts-ignore

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还有这种操作?
比起 as any 有什么优势吗?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那不是说明 id 改成 public 更适合?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nighca 你觉得呢 = =

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那不是说明 id 改成 public 更适合?

NIP: 或者也可以说,这边测试用例里就不太应该用 id?如果有充分的理由说明应该 private,而且这边应该用,那我觉得只要能绕过去,怎么操作都可以,我自己倾向更简单的做法

return utils.request(url, { method: 'GET' })
}

export type UploadUrlConfig = Partial<Pick<Config, 'upprotocol' | 'uphost' | 'region' | 'useCdnDomain'>>

/** 获取上传url */
export async function getUploadUrl(config: UploadUrlConfig, token: string): Promise<string> {
Copy link
Collaborator Author

@yinxulai yinxulai Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const result = await request<UploadCompleteData>(this.uploadUrl, {
method: 'POST',
body: formData,
await this.checkAndUpdateUploadHost()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

每次请求开始前都去更新 this 上的 host

@@ -35,6 +33,7 @@ export default class Direct extends Base {

this.logger.info('Direct progress finish.')
this.finishDirectProgress()
this.checkAndUnfreezeHost()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请求结束后去检查是否需要解冻

@@ -110,7 +113,11 @@ export function createXHR(): XMLHttpRequest {
return new XMLHttpRequest()
}

return window.ActiveXObject('Microsoft.XMLHTTP')
if (window.ActiveXObject) {
return new window.ActiveXObject('Microsoft.XMLHTTP')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@yinxulai yinxulai changed the title 添加高可用&补充测试 添加支持多 host 自动切换 & 补全测试 Apr 29, 2021
@yinxulai
Copy link
Collaborator Author

yinxulai commented Apr 29, 2021

NIP:经过测试,我们的 SDK 3.x 实际不支持 IE、1.x 是支持的(还测出了几个 BUG),暂时不考虑在当前 PR 进行兼容

Copy link
Collaborator

@lzfee0227 lzfee0227 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先开个头

另外处理一下这个呗
image

README.md Outdated Show resolved Hide resolved
src/utils/helper.test.ts Outdated Show resolved Hide resolved
src/logger/index.ts Show resolved Hide resolved
src/logger/index.test.ts Show resolved Hide resolved
new Logger('', true, 'OFF')
const last = new Logger('', true, 'OFF')
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还有这种操作?
比起 as any 有什么优势吗?

src/config/region.ts Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
@lzfee0227
Copy link
Collaborator

lzfee0227 commented Apr 29, 2021

我们的 SDK 3.x 实际不支持 IE

应该是支持的,只是某些版本 IE 不能用 xhr 的 onProgress 啥的接口而已
如果不支持,应该是中间某个版本改挂了,找到问题,修复一下
是否支持这件事看的是是否需要,不是通过测试推测出来的

@yinxulai
Copy link
Collaborator Author

另外处理一下这个呗
image

demo 打算重构,还修吗

src/config/region.ts Outdated Show resolved Hide resolved
src/upload/base.ts Outdated Show resolved Hide resolved
src/upload/base.ts Outdated Show resolved Hide resolved
src/upload/base.ts Outdated Show resolved Hide resolved
src/upload/base.ts Outdated Show resolved Hide resolved
src/upload/base.ts Outdated Show resolved Hide resolved
src/utils/config.ts Show resolved Hide resolved
src/errors/index.ts Outdated Show resolved Hide resolved
src/upload/hosts.ts Outdated Show resolved Hide resolved
src/upload/index.ts Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated
* code: `number` 请求错误状态码,可查阅码值对应 [说明](https://developer.qiniu.com/kodo/api/3928/error-responses)。
* isRequestError: 用于区分是否为 xhr 请求错误;当 xhr 请求出现错误并且后端通过 HTTP 状态码返回了错误信息时,该参数为 `true`;否则为 `undefined`。
* `QiniuNetworkError`
* code: `number` 固定为 `0`。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该说清楚这是 xhr.status 的那个 0
或者 xhr.status 为 0 会进这里
你注释里那句话也可以粘进来

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
@yinxulai yinxulai force-pushed the KODO-11659 branch 2 times, most recently from 8b5496f to 34c5d7c Compare May 14, 2021 07:46
README.md Outdated Show resolved Hide resolved
src/errors/index.ts Outdated Show resolved Hide resolved
src/upload/hosts.ts Outdated Show resolved Hide resolved
@yinxulai yinxulai force-pushed the KODO-11659 branch 2 times, most recently from 7302f84 to 23ba618 Compare May 14, 2021 08:39
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Collaborator

@lzfee0227 lzfee0227 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@yinxulai yinxulai merged commit c30a037 into qiniu:master May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants