GraphWalker / graphwalker-project

This is the repo for the Model-based testing tool GraphWalker.

Home Page:http://graphwalker.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RESTful restart command doesn't restart

BillyRuffian opened this issue · comments

I might be misunderstanding the purpose of this command. The documentation says it will reset the loaded models to their initial conditions. If I run a model with random(edge_coverage(100)) to completion, then call a restart command, the next call to hasNext returns {"result":"ok","hasNext":"false"}

I did a quick code review, and it looks like there is a problem.
Looking into it.

@BillyRuffian What version of graphwalker were you using?

I've tried both the 3.x and 4.0 branches, both from the pre-build binaries linked to on the GW doc site.

Update: Since the REST restart method looks like this:

  @PUT
  @Path("restart")
  @Produces("text/plain;charset=UTF-8")
  public String restart() {
    logger.debug("Received restart");
    JSONObject resultJson = new JSONObject();
    try {
      machine = new SimpleMachine(contexts);
      resultJson.put("result", "ok");
    } catch (Exception e) {
      e.printStackTrace();
      resultJson.put("result", "nok");
      resultJson.put("error", e.getMessage());
    }
    return resultJson.toString();
  }

The problem can be reproduced by this test.

  @Test
  public void resetMachine() throws Exception {
    Vertex v1 = new Vertex().setName("v1");
    Vertex v2 = new Vertex().setName("v2");
    Edge e1 = new Edge().setName("e1").setSourceVertex(v1).setTargetVertex(v2);
    Model model = new Model().addEdge(e1);
    Context context = new TestExecutionContext(model, new RandomPath(new VertexCoverage(100)));
    context.setNextElement(v1);
    Machine machine = new SimpleMachine(context);
    while (machine.hasNextStep()) {
      machine.getNextStep();
    }
    List<Element> expectedPath = Arrays.<Element>asList(
      v1.build(),
      e1.build(),
      v2.build()
    );
    List<Element> path = context.getProfiler().getExecutionPath().stream()
      .map(Execution::getElement).collect(Collectors.toList());
    assertThat(expectedPath, is(path));

    machine = new SimpleMachine(context);
    while (machine.hasNextStep()) {
      machine.getNextStep();
    }
    path = context.getProfiler().getExecutionPath().stream()
      .map(Execution::getElement).collect(Collectors.toList());
    assertThat(expectedPath, is(path));
  }
}

I'm working on a solution.