SUBTASKS 1.1 "before all" hook for ":1 "worldcup" database should exist"

In my case, the worldcup database is there, complete with the teams and games data on it, but somehow the code road can’t detect it

I’ve try to reset the progress and yeah, it works, but then crashed again after I finished my insert_data.sh script.

then I’ve try to delete the database and start over to create the database again, but still, after I create the worldcup database, code road can’t detect it

I wanna try to delete the session and start over again, but after see some people done doing it but having no good result, I’m afraid that’s not the main problem. So I guess freecodecamp team should look for deeper analysis about this since this struggle us to proceed to the next step of this course

I hope this explanation helps

When you hit Run on the CodeRoad tests can you share a screenshot of what appears in the test output?


(Open a terminal, click the OUTPUT tab, select CodeRoad (Tests) and then hit Run on the tests).

Here are the output for CodeRoad (Test):

I found out that when I reset the content inside insert_data.sh manually (deleting all query line except some preserved line in the beginning), the CddeRun start to works normally, so I think it’s related to my code or something. Since I’m not sure about it, I’ll put my code for insert_data.sh for further inspection

#! /bin/bash

if [[ $1 == "test" ]]
then
  PSQL="psql --username=postgres --dbname=worldcuptest -t --no-align -c"
else
  PSQL="psql --username=freecodecamp --dbname=worldcup -t --no-align -c"
fi

# Do not change code above this line. Use the PSQL variable above to query your database.

echo $($PSQL "TRUNCATE teams, games")

cat games.csv | while IFS="," read year round winner opponent winner_goals opponent_goals
do
  if [[ $year != "year" ]]
  then
    # get winner_id
    winner_id=$($PSQL "SELECT team_id FROM teams WHERE name='$winner'")

    # if not found
    if [[ -z $winner_id ]]
    then
      # insert major
      echo "$($PSQL "INSERT INTO teams(name) VALUES('$winner')")"
      # if [[ $INSERT_TEAM_RESULT == "INSERT 0 1" ]]
      # then
      #   echo Inserted into teams, $winner
      # fi

      # get new major_id
      winner_id=$($PSQL "SELECT team_id FROM teams WHERE name='$winner'")
    fi

    opponent_id=$($PSQL "SELECT team_id FROM teams WHERE name='$opponent'")

    # if not found
    if [[ -z $opponent_id ]]
    then
      # insert major
      echo "$($PSQL "INSERT INTO teams(name) VALUES('$opponent')")"
      # if [[ $INSERT_TEAM_RESULT == "INSERT 0 1" ]]
      # then
      #   echo Inserted into teams, $opponent
      # fi

      # get new major_id
      opponent_id=$($PSQL "SELECT team_id FROM teams WHERE name='$opponent'")
    fi

    echo "$($PSQL "INSERT INTO games(year, round, winner_goals, opponent_goals, winner_id, opponent_id) VALUES($year, '$round', $winner_goals, $opponent_goals, $winner_id, $opponent_id)")"
    # if [[ $INSERT_game_RESULT == "INSERT 0 1" ]]
    # then
    #   echo Inserted into games, $winner vs $opponent
    # fi

  fi
done

At a cursory glance, I can’t see anything wrong with your code.
The issue is most likely that the tests are running too slowly and causing timeouts.

Your error message appears to relate to the default mocha timeout, which can be changed in package.json (in the .freeCodeCamp directory).

The quickest way to adjust this is to open terminal and enter the following command:

sed 's/20000/50000/' -i /home/codeally/project/.freeCodeCamp/package.json

As you’ll see, the timeout has been adjust to 50secs now.
If you uncomment all of your code and Run the tests again, you should now have more luck!

1 Like

I’ve tried it, but with some customization (Instead of 50000, I’m using 100000, since 50000 still can’t solve the problem :sweat_smile: ) and IT WORKS for me!!

Thank you so much for your support @igorgetmeabrain , it helps a lot!!

tried this with 120000 and finally works!!!

For me, it worked when I added echo in front of the insert commands in insert_data.sh script.