Skip to content

Commit 0e56000

Browse files
committed
Wait for schemas to be loaded
1 parent e07bcf3 commit 0e56000

File tree

13 files changed

+140
-299
lines changed

13 files changed

+140
-299
lines changed

src/datastore/LMDB.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { stats } from './lmdb/Stats';
1212
import { encryptionStrategy } from './lmdb/Utils';
1313

1414
export class LMDBStoreFactory implements DataStoreFactory {
15-
private isClosed: boolean = false;
1615
private readonly log = LoggerFactory.getLogger('LMDB.Global');
1716
@Telemetry({ scope: 'LMDB.Global' }) private readonly telemetry!: ScopedTelemetry;
1817

@@ -87,18 +86,14 @@ export class LMDBStoreFactory implements DataStoreFactory {
8786
}
8887

8988
async close(): Promise<void> {
90-
if (this.isClosed) {
91-
return;
92-
}
89+
clearInterval(this.metricsInterval);
90+
clearTimeout(this.timeout);
9391

9492
// Clear the stores map but don't close individual stores
9593
// LMDB will close them when we close the environment
96-
clearInterval(this.metricsInterval);
97-
clearTimeout(this.timeout);
9894
this.stores.clear();
9995
await this.env.flushed;
10096
await this.env.close();
101-
this.isClosed = true;
10297
}
10398

10499
private cleanupOldVersions(): void {

src/server/CfnServer.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import { ServerComponents } from './ServerComponents';
6161

6262
const log = LoggerFactory.getLogger('CfnServer');
6363
export class CfnServer {
64-
private isClosed: boolean = false;
6564
private readonly components: ServerComponents;
6665

6766
constructor(
@@ -290,10 +289,6 @@ export class CfnServer {
290289
}
291290

292291
async close(): Promise<void> {
293-
if (this.isClosed) {
294-
return;
295-
}
296292
await closeSafely(this.providers, this.external, this.core);
297-
this.isClosed = true;
298293
}
299294
}

tst/e2e/CodeLens.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
1+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
22
import { CodeLens } from 'vscode-languageserver';
33
import { TestExtension } from '../utils/TestExtension';
44

55
describe('CodeLens', () => {
66
let client: TestExtension;
77

8-
beforeEach(async () => {
8+
beforeAll(async () => {
99
client = new TestExtension();
1010
await client.ready();
1111
});
1212

13-
afterEach(async () => {
13+
afterAll(async () => {
1414
await client.close();
1515
});
1616

tst/e2e/Completion.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
1+
import { beforeEach, afterEach, describe, it, expect } from 'vitest';
22
import { getSimpleYamlTemplateText, getSimpleJsonTemplateText } from '../utils/TemplateUtils';
33
import { TestExtension } from '../utils/TestExtension';
44

tst/e2e/DocumentSymbol.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
1+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
22
import { DocumentSymbol, SymbolKind } from 'vscode-languageserver';
33
import { TestExtension } from '../utils/TestExtension';
44

55
describe('DocumentSymbol', () => {
66
let client: TestExtension;
77

8-
beforeEach(async () => {
8+
beforeAll(async () => {
99
client = new TestExtension();
1010
await client.ready();
1111
});
1212

13-
afterEach(async () => {
13+
afterAll(async () => {
1414
await client.close();
1515
});
1616

tst/e2e/Goto.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
1+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
22
import { getYamlTemplate, getJsonTemplate } from '../utils/TemplateUtils';
33
import { TestExtension } from '../utils/TestExtension';
44

55
describe('Goto/Definition', () => {
66
let client: TestExtension;
77

8-
beforeEach(async () => {
8+
beforeAll(async () => {
99
client = new TestExtension();
1010
await client.ready();
1111
});
1212

13-
afterEach(async () => {
13+
afterAll(async () => {
1414
await client.close();
1515
});
1616

tst/e2e/Hover.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
1+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
22
import {
33
getComprehensiveYamlTemplate,
44
getYamlTemplate,
@@ -10,12 +10,12 @@ import { TestExtension } from '../utils/TestExtension';
1010
describe('Hover', () => {
1111
let client: TestExtension;
1212

13-
beforeEach(async () => {
13+
beforeAll(async () => {
1414
client = new TestExtension();
1515
await client.ready();
1616
});
1717

18-
afterEach(async () => {
18+
afterAll(async () => {
1919
await client.close();
2020
});
2121

tst/e2e/Hover.yaml.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, afterEach, describe, expect, test } from 'vitest';
1+
import { describe, expect, test, beforeAll, afterAll } from 'vitest';
22
import { Hover, MarkupContent, MarkupKind } from 'vscode-languageserver';
33
import { TextDocument } from 'vscode-languageserver-textdocument';
44
import { templateSectionDocsMap } from '../../src/artifacts/TemplateSectionDocs';
@@ -11,11 +11,11 @@ describe('Hover Tests', () => {
1111
const documentUri = 'file:///test.yaml';
1212
let extension: TestExtension;
1313

14-
beforeEach(() => {
14+
beforeAll(() => {
1515
extension = new TestExtension();
1616
});
1717

18-
afterEach(async () => {
18+
afterAll(async () => {
1919
await extension.close();
2020
});
2121

tst/utils/SchemaUtils.ts

Lines changed: 28 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -8,148 +8,63 @@ import { ResourceSchema } from '../../src/schema/ResourceSchema';
88
import { SamSchemas } from '../../src/schema/SamSchemas';
99
import { CloudFormationResourceSchema } from '../../src/schema/SamSchemaTransformer';
1010

11+
const loadSchema = (name: string) => readFileSync(join(__dirname, '..', 'resources', 'schemas', name), 'utf8');
12+
1113
export const Schemas = {
12-
S3Bucket: {
13-
fileName: 'file://aws-s3-bucket.json',
14-
get contents() {
15-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-s3-bucket.json'), 'utf8');
16-
},
17-
},
18-
EC2Instance: {
19-
fileName: 'file://aws-ec2-instance.json',
20-
get contents() {
21-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-ec2-instance.json'), 'utf8');
22-
},
23-
},
24-
IAMRole: {
25-
fileName: 'file://aws-iam-role.json',
26-
get contents() {
27-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-iam-role.json'), 'utf8');
28-
},
29-
},
30-
LambdaFunction: {
31-
fileName: 'file://aws-lambda-function.json',
32-
get contents() {
33-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-lambda-function.json'), 'utf8');
34-
},
35-
},
36-
EC2VPC: {
37-
fileName: 'file://aws-ec2-vpc.json',
38-
get contents() {
39-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-ec2-vpc.json'), 'utf8');
40-
},
41-
},
42-
EC2Subnet: {
43-
fileName: 'file://aws-ec2-subnet.json',
44-
get contents() {
45-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-ec2-subnet.json'), 'utf8');
46-
},
47-
},
14+
S3Bucket: { fileName: 'file://aws-s3-bucket.json', contents: loadSchema('aws-s3-bucket.json') },
15+
EC2Instance: { fileName: 'file://aws-ec2-instance.json', contents: loadSchema('aws-ec2-instance.json') },
16+
IAMRole: { fileName: 'file://aws-iam-role.json', contents: loadSchema('aws-iam-role.json') },
17+
LambdaFunction: { fileName: 'file://aws-lambda-function.json', contents: loadSchema('aws-lambda-function.json') },
18+
EC2VPC: { fileName: 'file://aws-ec2-vpc.json', contents: loadSchema('aws-ec2-vpc.json') },
19+
EC2Subnet: { fileName: 'file://aws-ec2-subnet.json', contents: loadSchema('aws-ec2-subnet.json') },
4820
EC2SecurityGroup: {
4921
fileName: 'file://aws-ec2-securitygroup.json',
50-
get contents() {
51-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-ec2-securitygroup.json'), 'utf8');
52-
},
22+
contents: loadSchema('aws-ec2-securitygroup.json'),
5323
},
5424
EC2LaunchTemplate: {
5525
fileName: 'file://aws-ec2-launchtemplate.json',
56-
get contents() {
57-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-ec2-launchtemplate.json'), 'utf8');
58-
},
26+
contents: loadSchema('aws-ec2-launchtemplate.json'),
5927
},
6028
AutoScalingGroup: {
6129
fileName: 'file://aws-autoscaling-autoscalinggroup.json',
62-
get contents() {
63-
return readFileSync(
64-
join(__dirname, '..', 'resources', 'schemas', 'aws-autoscaling-autoscalinggroup.json'),
65-
'utf8',
66-
);
67-
},
68-
},
69-
RDSDBInstance: {
70-
fileName: 'file://aws-rds-dbinstance.json',
71-
get contents() {
72-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-rds-dbinstance.json'), 'utf8');
73-
},
30+
contents: loadSchema('aws-autoscaling-autoscalinggroup.json'),
7431
},
32+
RDSDBInstance: { fileName: 'file://aws-rds-dbinstance.json', contents: loadSchema('aws-rds-dbinstance.json') },
7533
CloudWatchAlarm: {
7634
fileName: 'file://aws-cloudwatch-alarm.json',
77-
get contents() {
78-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-cloudwatch-alarm.json'), 'utf8');
79-
},
80-
},
81-
SNSTopic: {
82-
fileName: 'file://aws-sns-topic.json',
83-
get contents() {
84-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-sns-topic.json'), 'utf8');
85-
},
86-
},
87-
SSMParameter: {
88-
fileName: 'file://aws-ssm-parameter.json',
89-
get contents() {
90-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-ssm-parameter.json'), 'utf8');
91-
},
35+
contents: loadSchema('aws-cloudwatch-alarm.json'),
9236
},
37+
SNSTopic: { fileName: 'file://aws-sns-topic.json', contents: loadSchema('aws-sns-topic.json') },
38+
SSMParameter: { fileName: 'file://aws-ssm-parameter.json', contents: loadSchema('aws-ssm-parameter.json') },
9339
DynamoDBGlobalTable: {
9440
fileName: 'file://aws-dynamodb-globaltable.json',
95-
get contents() {
96-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-dynamodb-globaltable.json'), 'utf8');
97-
},
98-
},
99-
EC2SpotFleet: {
100-
fileName: 'file://aws-ec2-spotfleet.json',
101-
get contents() {
102-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-ec2-spotfleet.json'), 'utf8');
103-
},
41+
contents: loadSchema('aws-dynamodb-globaltable.json'),
10442
},
43+
EC2SpotFleet: { fileName: 'file://aws-ec2-spotfleet.json', contents: loadSchema('aws-ec2-spotfleet.json') },
10544
ELBv2ListenerRule: {
10645
fileName: 'file://aws-elasticloadbalancingv2-listenerrule.json',
107-
get contents() {
108-
return readFileSync(
109-
join(__dirname, '..', 'resources', 'schemas', 'aws-elasticloadbalancingv2-listenerrule.json'),
110-
'utf8',
111-
);
112-
},
46+
contents: loadSchema('aws-elasticloadbalancingv2-listenerrule.json'),
11347
},
11448
ELBv2Listener: {
11549
fileName: 'file://aws-elasticloadbalancingv2-listener.json',
116-
get contents() {
117-
return readFileSync(
118-
join(__dirname, '..', 'resources', 'schemas', 'aws-elasticloadbalancingv2-listener.json'),
119-
'utf8',
120-
);
121-
},
50+
contents: loadSchema('aws-elasticloadbalancingv2-listener.json'),
12251
},
12352
SecurityLakeSubscriberNotification: {
12453
fileName: 'file://aws-securitylake-subscribernotification.json',
125-
get contents() {
126-
return readFileSync(
127-
join(__dirname, '..', 'resources', 'schemas', 'aws-securitylake-subscribernotification.json'),
128-
'utf8',
129-
);
130-
},
54+
contents: loadSchema('aws-securitylake-subscribernotification.json'),
13155
},
13256
SyntheticsCanary: {
13357
fileName: 'file://aws-synthetics-canary.json',
134-
get contents() {
135-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-synthetics-canary.json'), 'utf8');
136-
},
58+
contents: loadSchema('aws-synthetics-canary.json'),
13759
},
13860
};
13961

14062
export const SamSchemaFiles = {
14163
ServerlessFunction: {
14264
fileName: 'file://aws-serverless-function.json',
143-
get contents() {
144-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-serverless-function.json'), 'utf8');
145-
},
146-
},
147-
ServerlessApi: {
148-
fileName: 'file://aws-serverless-api.json',
149-
get contents() {
150-
return readFileSync(join(__dirname, '..', 'resources', 'schemas', 'aws-serverless-api.json'), 'utf8');
151-
},
65+
contents: loadSchema('aws-serverless-function.json'),
15266
},
67+
ServerlessApi: { fileName: 'file://aws-serverless-api.json', contents: loadSchema('aws-serverless-api.json') },
15368
};
15469

15570
export function regionalSchemas(
@@ -225,7 +140,7 @@ export function samFileType(
225140
return map;
226141
}
227142

228-
export function getTestPrivateSchemas(): DescribeTypeOutput[] {
143+
const testPrivateSchemas = (() => {
229144
const schemas: DescribeTypeOutput[] = [];
230145
const privateSchemasDir = join(__dirname, '..', 'resources', 'private-schemas');
231146

@@ -242,4 +157,8 @@ export function getTestPrivateSchemas(): DescribeTypeOutput[] {
242157
}
243158

244159
return schemas;
160+
})();
161+
162+
export function getTestPrivateSchemas(): DescribeTypeOutput[] {
163+
return testPrivateSchemas;
245164
}

0 commit comments

Comments
 (0)