rusackas commented on code in PR #43215: URL: https://github.com/apache/superset/pull/43215#discussion_r4261251065
########## superset-frontend/src/utils/lazyWithRetry.test.tsx: ########## @@ -0,0 +1,76 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { Suspense } from 'react'; +import { render, screen } from 'spec/helpers/testing-library'; +import { lazyWithRetry, retryImport } from './lazyWithRetry'; + +const chunkLoadError = () => { + const error = new Error('Loading chunk 4169 failed.'); + error.name = 'ChunkLoadError'; + return error; +}; + +const Page = () => <div>Lazy page</div>; + +test('lazyWithRetry recovers from a transient ChunkLoadError (#41266)', async () => { + const factory = jest + .fn() + .mockRejectedValueOnce(chunkLoadError()) + .mockResolvedValue({ default: Page }); + + const LazyPage = lazyWithRetry(factory, { retryDelayMs: 0 }); + + render( + <Suspense fallback={<div>Loading</div>}> + <LazyPage /> + </Suspense>, + ); + + expect(await screen.findByText('Lazy page')).toBeInTheDocument(); + expect(factory).toHaveBeenCalledTimes(2); +}); + +test('retryImport exhausts its attempts and rethrows the last error (#41266)', async () => { + const factory = jest.fn().mockRejectedValue(chunkLoadError()); + + await expect( + retryImport(factory, { retries: 2, retryDelayMs: 0 }), Review Comment: Bikash's gone quiet on this one, so I just pushed a fix directly: two tests that pin `Math.random` to confirm the bound doubles each attempt, then run two concurrent imports with different draws and check their delays actually differ. Should close the gap you flagged instead of relying on `retryDelayMs: 0` alone. LGTM, thanks for catching it! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
