Skip to content

Commit

Permalink
chore: init metrics only if monitoring enabled (#5165)
Browse files Browse the repository at this point in the history
* add client creation test
* send dummy event instead of ResetCameraEvent
  • Loading branch information
jdrueckert authored Nov 7, 2023
1 parent e679a98 commit 0342fad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@
import org.joml.Vector3i;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.context.Context;
import org.terasology.engine.core.Time;
import org.terasology.engine.entitySystem.entity.EntityManager;
import org.terasology.engine.integrationenvironment.jupiter.IntegrationEnvironment;
import org.terasology.engine.logic.players.LocalPlayer;
import org.terasology.engine.logic.players.event.ResetCameraEvent;
import org.terasology.engine.network.ClientComponent;
import org.terasology.engine.network.NetworkMode;
import org.terasology.engine.registry.In;
import org.terasology.engine.world.WorldProvider;
import org.terasology.engine.world.block.BlockManager;
import org.terasology.unittest.stubs.DummyEvent;

import java.io.IOException;

@IntegrationEnvironment(networkMode = NetworkMode.LISTEN_SERVER)
public class ExampleTest {
private static final Logger logger = LoggerFactory.getLogger(ExampleTest.class);

@In
private WorldProvider worldProvider;
Expand All @@ -34,6 +37,13 @@ public class ExampleTest {
@In
private ModuleTestingHelper helper;

@Test
public void testClientCreation() {
logger.info("Starting test 'testClientCreation'");
Assertions.assertDoesNotThrow(helper::createClient);
logger.info("Done with test 'testClientCreation'");
}

@Test
public void testClientConnection() throws IOException {
int currentClients = Lists.newArrayList(entityManager.getEntitiesWith(ClientComponent.class)).size();
Expand Down Expand Up @@ -65,7 +75,7 @@ public void testSendEvent() throws IOException {
Context clientContext = helper.createClient();

// send an event to a client's local player just for fun
clientContext.get(LocalPlayer.class).getClientEntity().send(new ResetCameraEvent());
clientContext.get(LocalPlayer.class).getClientEntity().send(new DummyEvent());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ public void initialise(GameEngine engine, Context rootContext) {
if (rootContext.get(SystemConfig.class).monitoringEnabled.get()) {
advancedMonitor = new AdvancedMonitor();
advancedMonitor.setVisible(true);
initMicrometerMetrics(rootContext.get(Time.class));
}

initMicrometerMetrics(rootContext.get(Time.class));
}

/**
Expand Down

0 comments on commit 0342fad

Please sign in to comment.