Skip to content

Commit

Permalink
Merge pull request #2795 from zowe/fix/profcache/prof-by-type
Browse files Browse the repository at this point in the history
fix(ProfilesCache): Clear object caches before refresh
  • Loading branch information
traeok authored Apr 2, 2024
2 parents 143f5d1 + 6346758 commit e7b703f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.16.0-SNAPSHOT",
"version": "2.15.2",
"command": {
"version": {
"forcePublish": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/zowe-explorer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t

### Bug fixes

- Fixed an issue where the `ProfilesCache` class would retain old service profiles, even if they were removed from the team config. [#2395](https://github.com/zowe/zowe-explorer-vscode/issues/2395)

## `2.15.1`

### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ describe("ProfilesCache", () => {
expect(profCache.getAllTypes().length).toEqual(0);
expect(mockLogError).toHaveBeenCalledWith(fakeError);
});

it("should clear the profilesByType and defaultProfileByType maps before reloading profiles", async () => {
const profCache = new ProfilesCache({ ...fakeLogger, error: mockLogError } as unknown as zowe.imperative.Logger);
const profInfoMock = jest.spyOn(profCache, "getProfileInfo").mockRejectedValueOnce("some error");
const errorMock = jest.spyOn((profCache as any).log, "error").mockImplementation();
(profCache as any).profilesByType["test-type"] = { name: "someProf" as any };
(profCache as any).defaultProfileByType["test-type"] = { name: "someProf" as any };
await profCache.refresh();
expect((profCache as any).profilesByType.size).toBe(0);
expect((profCache as any).defaultProfileByType.size).toBe(0);
expect(errorMock).toHaveBeenCalledWith("some error");
profInfoMock.mockRestore();
errorMock.mockRestore();
});
});

describe("validateAndParseUrl", () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/zowe-explorer-api/src/profiles/ProfilesCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ export class ProfilesCache {
public async refresh(apiRegister?: ZoweExplorerApi.IApiRegisterClient): Promise<void> {
this.allProfiles = [];
this.allTypes = [];
this.profilesByType.clear();
this.defaultProfileByType.clear();
let mProfileInfo: zowe.imperative.ProfileInfo;
try {
mProfileInfo = await this.getProfileInfo();
Expand Down

0 comments on commit e7b703f

Please sign in to comment.