Repository navigation
Conversation
| ngOnDestroy() { | ||
| for (const subscription of this.loaders.values()) { | ||
| subscription.unsubscribe(); | ||
| } | ||
| this.loaders.clear(); | ||
| this.syncLoading(); | ||
| } |
There was a problem hiding this comment.
Because GlobalLoaderService is providedIn: 'root', ngOnDestroy() only runs when the root injector / TestBed is torn down—not when short-lived components implementing GlobalLoader (such as HistoryComponent, ContactComponent, ContactDetailsComponent, RdapEditComponent, EppPasswordEditComponent, and SecurityEditComponent) are destroyed on route/view changes while a request is still in flight. Those components will still retain a 10s timer in this.loaders and invoke loadingTimeout() (MatSnackBar.open) after component destruction unless they call stopGlobalLoader(this) on teardown.
| this.getUserData().subscribe(() => { | ||
| this.globalLoader.stopGlobalLoader(this); | ||
| }); | ||
| this.globalLoader.startGlobalLoader(this); |
There was a problem hiding this comment.
RegistrarService (console-webapp/src/app/registrar/registrar.service.ts lines 101–108) has this exact same constructor bug pattern and was left unfixed:
this.loadRegistrars().subscribe(...)runs beforethis.globalLoader.startGlobalLoader(this), so synchronousof(...)mocks leaveglobalLoader.isLoading()stucktrueand leak a 10s timer that fires'Timeout loading registrars'(which is whyregistrar.service.spec.tshad to use a deferredSubject).- No
finalize()on error (isLoading()staystruefor 10s andregistrarsLoadedhangs forever). - No
OnDestroyto unsubscribe the in-flight/console-api/registrarsrequest.
| this.userDataSubscription = this.getUserData() | ||
| .pipe(finalize(() => this.globalLoader.stopGlobalLoader(this))) | ||
| .subscribe(); |
There was a problem hiding this comment.
BackendService.getUserData() calls this.errorCatcher<UserData>(err) with no mockData, which rethrows via throwError(() => error). In RxJS 7+, calling .subscribe() with no error observer forwards errors to reportUnhandledError (setTimeout(() => { throw err; })), which surfaces as an uncaught exception if /console-api/userdata fails (including in Vitest fake-timer tests when advancing timers). Pass { error: () => {} } (or open an error snackbar) in .subscribe(...).
| it('should open snackbar on loadingTimeout if request does not resolve in time', () => { | ||
| vi.useFakeTimers(); | ||
| const pendingUserData$ = new Subject<UserData>(); | ||
|
|
||
| TestBed.configureTestingModule({ | ||
| providers: [ | ||
| BackendService, | ||
| GlobalLoaderService, | ||
| MatSnackBar, | ||
| provideHttpClient(), | ||
| provideHttpClientTesting(), | ||
| ], | ||
| }); | ||
| const backend = TestBed.inject(BackendService); | ||
| vi.spyOn(backend, 'getUserData').mockReturnValue( | ||
| pendingUserData$.asObservable() | ||
| ); | ||
| const snackBarSpy = vi | ||
| .spyOn(TestBed.inject(MatSnackBar), 'open') | ||
| .mockReturnValue({} as never); | ||
|
|
||
| TestBed.inject(UserDataService); | ||
| vi.advanceTimersByTime(10000); | ||
|
|
||
| expect(snackBarSpy).toHaveBeenCalledWith('Timeout loading user data'); | ||
| }); |
There was a problem hiding this comment.
The PR description notes that finalize() stops the loader on completion/error/unsubscribe, but there is no test covering the error path (e.g., throwError(...) + vi.advanceTimersByTime(10000)). Adding an error test case here will also catch the unhandled error from .subscribe() having no error observer.
GlobalLoaderService schedules 10-second RxJS timeout subscriptions for
active loaders, but did not implement OnDestroy to unsubscribe them when
the Angular injector is torn down. In Vitest runs exceeding 10 seconds
(such as CI), tests that instantiate UserDataService without resolving
the initial /console-api/userdata HTTP request leave a dangling timer
that fires after TestBed destruction and throws NG0205 when calling
MatSnackBar.open in UserDataService.loadingTimeout().
- Implement OnDestroy in GlobalLoaderService to unsubscribe and clear
all active loader timers on teardown, and unsubscribe any existing
loader subscription before replacing it in startGlobalLoader().
- Implement OnDestroy in all short-lived GlobalLoader components
(HistoryComponent, ContactComponent, ContactDetailsComponent,
RdapEditComponent, EppPasswordEditComponent, SecurityEditComponent)
to call stopGlobalLoader(this) on component teardown so mid-flight
route/view changes do not leak 10s timers.
- Fix constructor loader lifecycle in both UserDataService and
RegistrarService: start the global loader before subscribing so
synchronous completions do not leak a timer, use finalize() to stop
the loader (and resolve registrarsLoaded) on completion/error/
unsubscribe, pass an error observer ({ error: () => {} }) so RxJS
does not trigger reportUnhandledError on rethrown HTTP errors, and
implement OnDestroy to unsubscribe in-flight initial requests.
- Add unit tests in userData.service.spec.ts, registrar.service.spec.ts,
shared.spec.ts, history.component.spec.ts, contact.component.spec.ts,
rdap.component.spec.ts, and security.component.spec.ts covering
TestBed teardown, ngOnDestroy, synchronous completion, error handling,
duplicate startGlobalLoader calls, and short-lived component teardown.
BUG= http://b/588453384
9303c16 to
a48c8e6
Compare
GlobalLoaderServiceschedules 10-second RxJS timeout subscriptions for active loaders, but did not implementOnDestroyto unsubscribe them when the Angular injector is torn down. In Vitest runs exceeding 10 seconds (such as CI), tests that instantiateUserDataServicewithout resolving the initial/console-api/userdataHTTP request leave a dangling timer that fires afterTestBeddestruction and throwsNG0205when callingMatSnackBar.openinUserDataService.loadingTimeout().OnDestroyinGlobalLoaderServiceto unsubscribe and clear all active loader timers on teardown, and unsubscribe any existing loader subscription before replacing it instartGlobalLoader().OnDestroyin all short-livedGlobalLoadercomponents (HistoryComponent,ContactComponent,ContactDetailsComponent,RdapEditComponent,EppPasswordEditComponent,SecurityEditComponent) to callstopGlobalLoader(this)on component teardown so mid-flight route/view changes do not leak 10s timers.UserDataServiceandRegistrarService: start the global loader before subscribing so synchronous completions do not leak a timer, usefinalize()to stop the loader (and resolveregistrarsLoaded) on completion/error/unsubscribe, pass an error observer ({ error: () => {} }) so RxJS does not triggerreportUnhandledErroron rethrown HTTP errors, and implementOnDestroyto unsubscribe in-flight initial requests.userData.service.spec.ts,registrar.service.spec.ts,shared.spec.ts,history.component.spec.ts,contact.component.spec.ts,rdap.component.spec.ts, andsecurity.component.spec.tscoveringTestBedteardown,ngOnDestroy, synchronous completion, error handling, duplicatestartGlobalLoadercalls, and short-lived component teardown.BUG= http://b/588453384
This change is