Skip to content

Conversation

kjin
Copy link
Contributor

@kjin kjin commented Mar 17, 2018

This change adds a class that abstracts the "singleton" concept and uses it for the TraceWriter singleton. This makes singletons (including the future PluginLoader class) easier to mock.

I recommend looking at each commit separately

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 17, 2018
@kjin kjin changed the title refactor: don't pass callback to traceWriter.create refactor: externalize singleton accessors from trace writer Mar 17, 2018
@codecov
Copy link

codecov bot commented Mar 17, 2018

Codecov Report

Merging #694 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #694      +/-   ##
==========================================
+ Coverage   90.06%   90.15%   +0.09%     
==========================================
  Files          29       29              
  Lines        1419     1422       +3     
  Branches      288      287       -1     
==========================================
+ Hits         1278     1282       +4     
  Misses         57       57              
+ Partials       84       83       -1
Impacted Files Coverage Δ
src/trace-writer.ts 88.52% <100%> (+0.06%) ⬆️
src/util.ts 92.85% <100%> (+1.07%) ⬆️
src/index.ts 90% <100%> (ø) ⬆️

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 9d56e84...3097495. Read the comment docs.

src/util.ts Outdated
}

/**
* An class that provides access to a singleton.

This comment was marked as spam.

This comment was marked as spam.

src/util.ts Outdated
export class Singleton<T, Config> {
private singleton: T|null = null;

constructor(private implementation: ClassOf<T, Config>) {}

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@kjin kjin force-pushed the t-w-s branch 2 times, most recently from 0776eb1 to 79af06b Compare March 19, 2018 16:31
src/util.ts Outdated
* Instances of this type should only be constructed in module scope.
*/
export class Singleton<T, Config> {
private singleton: T|null = null;

This comment was marked as spam.

This comment was marked as spam.

let singleton: TraceWriter|null = null;
disableTraceWriter();
export function setTraceWriterEnabled(enabled: boolean) {
traceWriter['implementation'] = enabled ? TraceWriter : TestTraceWriter;

This comment was marked as spam.

This comment was marked as spam.

constructor(private implementation: Constructor<T, Config>) {}

create(logger: Logger, config: Config&{forceNewAgent_: boolean}): T {
create(logger: Logger, config: Config&{forceNewAgent_?: boolean}): T {

This comment was marked as spam.

This comment was marked as spam.

@kjin
Copy link
Contributor Author

kjin commented Mar 19, 2018

Node 9 CI is failing only because the way it was rebuilt (through Circle workflows) doesn't allow it to correctly detect whether it should run system tests. This should not be reflected on master

@kjin kjin merged commit 5338a93 into googleapis:master Mar 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants